logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: Logger.setLevel() not supported in 2.0?
Date Wed, 23 Jul 2014 15:25:39 GMT
In Log4j 2 Logger.setLevel() might now work the way you would expect.  It would change the
level of the specific logger, but it would not affect child loggers.  So if you had a Logger(com.foo)
and Logger(com.foo.bar), which both had effective levels of “error” and then you called
setLevel on Logger(com.foo) with “debug”, events logged to Logger(com.foo.bar) would still
be at “error”.  To change the level in a manner similar to Log4j 1 you would want to obtain
the appropriate LoggerConfig, change its Level and then call the LoggerContext’s updateLoggers()
method.  Needless to say, this is not something that is exposed at the API layer and ties
you to the specifics of how Log4j 2 is implemented.

FWIW, changing the Level of the LoggerConfig is supported via JMX, so you can create tooling
that interacts with that.


On Jul 22, 2014, at 11:32 PM, Merten Schumann <Merten.Schumann@asg.com> wrote:

> Hello,
> from "Converting to the Log4j 2 API":
> Calls to org.apache.log4j.Logger.setLevel() or similar methods are not supported in the
> Applications should remove these.
> Could imagine the reason, checking getLevel() is final, so it's quick.
> But, when you have in your program your good old fixed static Logger log, it's often
helpful to toggle its logger level at runtime, when the method that should be investigated
is reached in the code or in the debugger ... enable DEBUG output and disable it again ...
> Am I missing something? Nobody else missing this feature? :-)
> Thanx
>   Merten

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message