Java 类org.apache.logging.log4j.spi.StandardLevel 实例源码

项目:microservice-mock    文件:LogManager.java   
/**
 * Auxiliary method to change the log level.
 *
 * @param logLevel
 *  The log level to set.
 *
 * @return
 *  A ResponseContext containing the result of the command.
 */
public static ResponseContext changeLogLevel(String logLevel) {
    ResponseContext responseContext = new ResponseContext();
    responseContext.setContentType(ResponseContext.PLAIN_TEXT_CONTENT_TYPE);
    LoggerContext loggerContext = LoggerContext.getContext(false);
    Configuration configuration = loggerContext.getConfiguration();
    LoggerConfig rootLogger = configuration.getRootLogger();
    if (rootLogger != null) {
        switch (StandardLevel.getStandardLevel(Level.toLevel(logLevel, Level.INFO).intLevel())) {
            case ERROR:
                rootLogger.setLevel(Level.ERROR);
                responseContext.setResponse("Log level changed to ERROR");
                break;
            case WARN:
                rootLogger.setLevel(Level.WARN);
                responseContext.setResponse("Log level changed to WARN");
                break;
            case INFO:
                rootLogger.setLevel(Level.INFO);
                responseContext.setResponse("Log level changed to INFO");
                break;
            case DEBUG:
                rootLogger.setLevel(Level.DEBUG);
                responseContext.setResponse("Log level changed to DEBUG");
                break;
            case OFF:
                rootLogger.setLevel(Level.OFF);
                responseContext.setResponse("Logging switched off");
                break;
            default:
                responseContext.setResponse("Log level unchanged, unsupported level: " + logLevel);
        }
        loggerContext.updateLoggers();
    } else {
        responseContext.setResponse("Unable to change log level, no ROOT logger found...");
        responseContext.setErrorCode(String.valueOf(HttpURLConnection.HTTP_INTERNAL_ERROR));
    }
    return responseContext;
}
项目:spectator    文件:LevelTagTest.java   
@Test
public void levels() {
  for (StandardLevel std : StandardLevel.values()) {
    Level level = Level.getLevel(std.name());
    Assert.assertEquals(std, LevelTag.get(level).standardLevel());
  }
}
项目:logging-log4j2    文件:Level.java   
private Level(final String name, final int intLevel) {
    if (Strings.isEmpty(name)) {
        throw new IllegalArgumentException("Illegal null or empty Level name.");
    }
    if (intLevel < 0) {
        throw new IllegalArgumentException("Illegal Level int less than zero.");
    }
    this.name = name;
    this.intLevel = intLevel;
    this.standardLevel = StandardLevel.getStandardLevel(intLevel);
    if (LEVELS.putIfAbsent(name, this) != null) {
        throw new IllegalStateException("Level " + name + " has already been defined.");
    }
}
项目:logging-log4j2    文件:Level.java   
/**
 * Gets the standard Level values as an enum.
 *
 * @return an enum of the standard Levels.
 */
public StandardLevel getStandardLevel() {
    return standardLevel;
}