    001    /*
    002     * Licensed to the Apache Software Foundation (ASF) under one or more
    003     * contributor license agreements. See the NOTICE file distributed with
    004     * this work for additional information regarding copyright ownership.
    005     * The ASF licenses this file to You under the Apache license, Version 2.0
    006     * (the "License"); you may not use this file except in compliance with
    007     * the License. You may obtain a copy of the License at
    008     *
    009     *      http://www.apache.org/licenses/LICENSE-2.0
    010     *
    011     * Unless required by applicable law or agreed to in writing, software
    012     * distributed under the License is distributed on an "AS IS" BASIS,
    013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014     * See the license for the specific language governing permissions and
    015     * limitations under the license.
    016     */
    017    package org.apache.logging.log4j.spi;
    018
    019    import java.util.EnumSet;
    020
    021    /**
    022     * Standard Logging Levels as an enumeration for use internally. This enum is used as a parameter in
    023     * any public APIs.
    024     */
    025    public enum StandardLevel {
    026
    027        /**
    028         * No events will be logged.
    029         */
    030        OFF(0),
    031
    032        /**
    033         * A severe error that will prevent the application from continuing.
    034         */
    035        FATAL(100),
    036
    037        /**
    038         * An error in the application, possibly recoverable.
    039         */
    040        ERROR(200),
    041
    042        /**
    043         * An event that might possible lead to an error.
    044         */
    045        WARN(300),
    046
    047        /**
    048         * An event for informational purposes.
    049         */
    050        INFO(400),
    051
    052        /**
    053         * A general debugging event.
    054         */
    055        DEBUG(500),
    056
    057        /**
    058         * A fine-grained debug message, typically capturing the flow through the application.
    059         */
    060        TRACE(600),
    061
    062        /**
    063         * All events should be logged.
    064         */
    065        ALL(Integer.MAX_VALUE);
    066
    067
    068        private final int intLevel;
    069
    070        private static final EnumSet<StandardLevel> levelSet = EnumSet.allOf(StandardLevel.class);
    071
    072        private StandardLevel(final int val) {
    073            intLevel = val;
    074        }
    075
    076        /**
    077         * Returns the integer value of the Level.
    078         * @return the integer value of the Level.
    079         */
    080        public int intLevel() {
    081            return intLevel;
    082        }
    083
    084        /**
    085         * Method to convert custom Levels into a StandardLevel for conversion to other systems.
    086         * @param intLevel The integer value of the Level.
    087         * @return The StandardLevel.
    088         */
    089        public static StandardLevel getStandardLevel(final int intLevel) {
    090            StandardLevel level = StandardLevel.OFF;
    091            for (final StandardLevel lvl : levelSet) {
    092                if (lvl.intLevel() > intLevel) {
    093                    break;
    094                }
    095                level = lvl;
    096            }
    097            return level;
    098        }
    099    }