001package org.slf4j.event;
002
003import static org.slf4j.event.EventConstants.DEBUG_INT;
004import static org.slf4j.event.EventConstants.ERROR_INT;
005import static org.slf4j.event.EventConstants.INFO_INT;
006import static org.slf4j.event.EventConstants.TRACE_INT;
007import static org.slf4j.event.EventConstants.WARN_INT;
008
009/**
010 * SLF4J's internal representation of Level.
011 * 
012 * 
013 * @author Ceki Gülcü
014 * @since 1.7.15
015 */
016public enum Level {
017
018    ERROR(ERROR_INT, "ERROR"), WARN(WARN_INT, "WARN"), INFO(INFO_INT, "INFO"), DEBUG(DEBUG_INT, "DEBUG"), TRACE(TRACE_INT, "TRACE");
019
020    private final int levelInt;
021    private final String levelStr;
022
023    Level(int i, String s) {
024        levelInt = i;
025        levelStr = s;
026    }
027
028    public int toInt() {
029        return levelInt;
030    }
031
032    public static Level intToLevel(int levelInt) {
033        switch (levelInt) {
034        case (TRACE_INT):
035            return TRACE;
036        case (DEBUG_INT):
037            return DEBUG;
038        case (INFO_INT):
039            return INFO;
040        case (WARN_INT):
041            return WARN;
042        case (ERROR_INT):
043            return ERROR;
044        default:
045            throw new IllegalArgumentException("Level integer [" + levelInt + "] not recognized.");
046        }
047    }
048
049    /**
050     * Returns the string representation of this Level.
051     */
052    public String toString() {
053        return levelStr;
054    }
055
056}