[slf4j-user] Reconfigure during runtime

Per Lindberg per.lindberg at facilitylabs.com
Wed Feb 17 10:24:16 CET 2010


Ceki Gülcü wrote:
> On 16/02/2010 10:05 AM, Per Lindberg wrote:
>> Is there a way to reconfigure slf4j during runtime, in the same
>> manner as in log4j with e.g.
>>
>> Logger root = Logger.getRootLogger();
>> root.setLevel(Level.DEBUG);
>>
>> I have a webapp using slf4j over log4j that would benefit from this,
>> But the above log4j hack doesn't work, presumably because slf4j isn't
>> notified of the change.
>>
>> Is there a canonical way of doing this?
> 
> SLF4J loggers do not have setters or getters for levels. You would
> need to use the log4j API directly to set logger levels.

I have tried just that, using the code snippet above.
It calls log4j directly:

   org.apache.log4j.Logger root = org.apache.log4j.Logger.getRootLogger();
   root.setLevel(org.apache.log4j.Level.DEBUG);

No luck.

(I had then plans to do it more specifically by passing request
parameters with specific log level and class path:

   org.apache.log4j.Logger logger =   org.apache.log4j.Logger.getLogger(classPath);
   org.apache.log4j.Level level = org.apache.log4j.Level.toLevel(logLevel);
   logger.setLevel(level);

Since I import slf4j, I of course must specify the full package
qualification for the log4j calls.)

> This would tie your code to log4j. 

Ah, you mean that I would have to throw out slf4j,
and use log4j directly for logging?

> However, it would do so at one single point
> instead of throughout your application.

Sorry, I didn't understand that.

Best regards,
Per Lindberg



More information about the slf4j-user mailing list