package net.northking.cctp.element.log;

/**
 * Log level
 *
 * @author fengxiang.zhang
 * @since 1.0
 */
public enum Level {

    ERROR(LevelConst.ERROR_INT, "ERROR"),
    WARN(LevelConst.WARN_INT, "WARN"),
    INFO(LevelConst.INFO_INT, "INFO"),
    DEBUG(LevelConst.DEBUG_INT, "DEBUG");

    private int levelInt;
    private String levelStr;

    Level(int i, String s) {
        levelInt = i;
        levelStr = s;
    }

    public int toInt() {
        return levelInt;
    }

    public String toString() {
        return levelStr;
    }

    public static Level formatLevel(String level) {
        for (Level e : Level.values()) {
            if (e.levelStr.equalsIgnoreCase(level)) {
                return e;
            }
        }
        throw new IllegalArgumentException(String.format("非法的日志级别:%s", level));
    }

    class LevelConst {
        final public static int DEBUG_INT = 10;
        final public static int INFO_INT = 20;
        final public static int WARN_INT = 30;
        final public static int ERROR_INT = 40;
    }
}