[slf4j-user] Reconfigure during runtime

Ceki Gülcü ceki at qos.ch
Wed Feb 17 11:38:03 CET 2010


On 17/02/2010 11:19 AM, Per Lindberg wrote:

> It compiles and runs all right. But it doesn't change the log level.
>
> I have a log4j.properties that sets my default log level to INFO:
>
> log4j.rootLogger=WARN
> log4j.logger.com.facilitylabs.controlserver=INFO,SERVERLOG
>
> where SERVERLOG is a org.apache.log4j.RollingFileAppender.
> Works fine. Now, I have sprinkled my code with slf4j calls.
> Every method begins with
>
> log.debug("fooMethod({},{})", param1, param2);
>
> Now, suppose that I suspect that something is wrong in the running
> production server. I don't want to stop it, just tell it to start
> logging on DEBUG level for class com.facilitylabs.foo.barServlet .
> Via the web GUI I POST a command to the above code. But no debug
> messages are written to my log file. (INFO messages work fine,
> as usual).
>
> Is this because I change log level in the log4j layer,
> but not in the slf4j layer?



You can't change the logging levels at the SLF4J layer because SLF4J
does not keep its own levels, it delegates all decisions to the
underlying logging framework. As for parametrized logging, if you look
at the SLF4J code, you'll see that it asks the underlying logging
framework whether to filter the message or not. In short, you can't
set the level of loggers via the SLF4J API. So you should not worry
about setting SLF4J levels.

If you wish to change logging configuration at runtime, logback has
support configuration file reloading which you might find useful:

   http://logback.qos.ch/manual/configuration.html#autoScan

Cheers,

--
Ceki


More information about the slf4j-user mailing list