Re: dynamic logging control

Ralph Goers <[email protected]> Tue, 8 Nov 2016 07:05:19 -0700
Newsgroups gmane.comp.apache.logging
Message-ID <[email protected]>
Are you looking at the Logger or LoggerConfig.  Log4j 2 separates Loggers from their configuration. 

To modify a logLevel you need to do:

LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
loggerConfig.setLevel(level);
context.updateLoggers();

This process locates the configured Logger for the desired logger name, sets its level and then modifies all the Loggers that use the LoggerConfig.

Ralph

> On Nov 8, 2016, at 6:51 AM, Benson Margulies <[email protected]> wrote:
> 
> In old log4j, I've  maintained a JUnit rule that temporarily throttles a logger.
> 
> In log4j2, I see a setLevel, but no getLevel, which rather screws up
> 'temporarily'.
> 
> What am I missing?
>