Re: dynamic logging control

Benson Margulies <[email protected]> Tue, 8 Nov 2016 09:10:56 -0500
Newsgroups gmane.comp.apache.logging
Message-ID <CALm0H566EC85Z0x56_K++d0qeR_6Yg1YGKKWL+Vb0gx3tuz1qA@mail.gmail.com>
I read http://logging.apache.org/log4j/2.x/manual/migration.html which
is how I got into the neighborhood of

org.apache.logging.log4j.core.config.Configurator.setLevel

I can follow your recipe instead.



On Tue, Nov 8, 2016 at 9:05 AM, Ralph Goers <[email protected]> wrote:
> 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?
>>
>
>