Reputation: 18643
In log4j version 2, how does one accomplish what previous versions of log4j did when called from Java code thus:
Logger.getRootLogger().setLevel( Level.TRACE );
I want, depending on a utility's command-line option, to turn on tracing.
Upvotes: 1
Views: 167
Reputation: 6180
Try this
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(level);
ctx.updateLoggers();
Upvotes: 2