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 */
017package org.apache.logging.log4j.spi;
018
019import java.util.EnumSet;
020
021/**
022 * Standard Logging Levels as an enumeration for use internally. This enum is used as a parameter in any public APIs.
023 */
024public enum StandardLevel {
025
026    /**
027     * No events will be logged.
028     */
029    OFF(0),
030
031    /**
032     * A severe error that will prevent the application from continuing.
033     */
034    FATAL(100),
035
036    /**
037     * An error in the application, possibly recoverable.
038     */
039    ERROR(200),
040
041    /**
042     * An event that might possible lead to an error.
043     */
044    WARN(300),
045
046    /**
047     * An event for informational purposes.
048     */
049    INFO(400),
050
051    /**
052     * A general debugging event.
053     */
054    DEBUG(500),
055
056    /**
057     * A fine-grained debug message, typically capturing the flow through the application.
058     */
059    TRACE(600),
060
061    /**
062     * All events should be logged.
063     */
064    ALL(Integer.MAX_VALUE);
065
066    private static final EnumSet<StandardLevel> LEVELSET = EnumSet.allOf(StandardLevel.class);
067
068    private final int intLevel;
069
070    StandardLevel(final int val) {
071        intLevel = val;
072    }
073
074    /**
075     * Returns the integer value of the Level.
076     * 
077     * @return the integer value of the Level.
078     */
079    public int intLevel() {
080        return intLevel;
081    }
082
083    /**
084     * Method to convert custom Levels into a StandardLevel for conversion to other systems.
085     * 
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}