[slf4j-user] Reconfigure during runtime

Per Lindberg per.lindberg at facilitylabs.com
Wed Feb 17 11:46:12 CET 2010


Ceki Gülcü wrote:
> 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.

Okay, that's nice. Does that mean that if I change the logging level
to DEBUG at the LOG4J level, then calls to SLF4J log.debug() will
start to output messages? (I have failed to make that work, but
perhaps I have just overlooked some small detail...)

> 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

But I can't modify any files in a running JEE web application.
(And, besides, logback is not an option for me right now).

Can't I just change the logging level by calling log4j
logger.setLevel(level) ?

Salutations,
Per



More information about the slf4j-user mailing list