Java Code Examples for ch.qos.logback.classic.Level#valueOf()

The following examples show how to use ch.qos.logback.classic.Level#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoggerOverrideConfigChangeHandler.java    From terracotta-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void validate(NodeContext nodeContext, Configuration change) throws InvalidConfigChangeException {
  String logger = change.getKey();
  String level = change.getValue();

  // verify enum
  if (level != null) {
    try {
      Level.valueOf(level);
    } catch (RuntimeException e) {
      throw new InvalidConfigChangeException("Illegal level: " + level, e);
    }
  }

  // verify we can access the logger
  LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
  Logger logbackLogger = loggerContext.getLogger(logger);

  // verify illegal op
  if (Logger.ROOT_LOGGER_NAME.equals(logbackLogger.getName()) && level == null) {
    throw new InvalidConfigChangeException("Cannot remove the root logger");
  }
}
 
Example 2
Source File: LogManagerController.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PreAuthorize("hasAnyRole('ROLE_SU')")
@PostMapping("/logger/{loggerName}/{loggerLevel}")
@ResponseStatus(HttpStatus.OK)
public void updateLogLevel(
    @PathVariable(value = "loggerName") String loggerName,
    @PathVariable(value = "loggerLevel") String loggerLevelStr) {
  // SLF4j logging facade does not support runtime change of log level, cast to Logback logger
  org.slf4j.Logger logger = LoggerFactory.getLogger(loggerName);
  if (!(logger instanceof ch.qos.logback.classic.Logger)) {
    throw new RuntimeException("Root logger is not a Logback logger");
  }
  ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) logger;

  // update log level
  Level loggerLevel;
  try {
    loggerLevel = Level.valueOf(loggerLevelStr);
  } catch (IllegalArgumentException e) {
    throw new RuntimeException("Invalid log level [" + loggerLevelStr + "]");
  }
  logbackLogger.setLevel(loggerLevel);
}
 
Example 3
Source File: CommandLineArguments.java    From simulacron with Apache License 2.0 5 votes vote down vote up
@Override
public Level convert(String value) {
  Level convertedValue = Level.valueOf(value);

  if (convertedValue == null) {
    throw new ParameterException("Value " + value + "can not be converted to a logging level.");
  }
  return convertedValue;
}
 
Example 4
Source File: LogbackLoggingFacade.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean setLogLevel(@Nonnull final LoggerConfig loggerConfig) {
    final Level level = Level.valueOf(loggerConfig.getLevel().getIdentifier());
    final String loggerName = loggerConfig.getLogger().orElse(Logger.ROOT_LOGGER_NAME);
    final Logger logger = (Logger) LoggerFactory.getLogger(loggerName);

    logger.setLevel(level);

    return logger.isEnabledFor(level);
}
 
Example 5
Source File: StartupAppender.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public StartupAppender()
{
    super();
    setName(StartupAppender.class.getName());
    String overriddenLogLevel = System.getProperty(PROPERTY_STARTUP_FAILOVER_CONSOLE_LOG_LEVEL);
    if (overriddenLogLevel != null)
    {
        _consoleAppenderAcceptLogLevel = Level.valueOf(overriddenLogLevel);
    }
}
 
Example 6
Source File: AppMain.java    From chassis with Apache License 2.0 5 votes vote down vote up
private static void initializeLogging(Arguments arguments) {
    //bootstrap depends on logback for logging console output. if the clientApplication does not want logback, they
    //need to exclude logback from their project dependencies and initialize their own logging
    try {
        AppMain.class.getClassLoader().loadClass("ch.qos.logback.classic.LoggerContext");
    } catch (ClassNotFoundException e) {
        System.err.println("No Logback found in classpath. Skipping logging initialization. This is expected if you are configuring the logging system yourself. If you are not configuring logging yourself and would like to use logging provided by java-bootstrap, ensure that the Logback dependency jar exists in your classpath.");
        return;
    }

    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();
    BasicConfigurator.configure(context);
    ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

    Level level = Level.valueOf(arguments.logLevel.name().toUpperCase());
    logger.setLevel(level);

    logger.info("Initialized logging at {} level", level);
}
 
Example 7
Source File: LogbackLevels.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Convert a {@link LoggerLevel} into a Logback {@link Level}.
 */
public static Level convert(final LoggerLevel level) {
  return Level.valueOf(level.name());
}
 
Example 8
Source File: LogbackLogManager.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
private Level convertLevel(LoggingConfig.Level level) {
    return Level.valueOf(level.name());
}