[slf4j-user] Conditional configuration

Steve Cohen scohen at javactivity.org
Tue Mar 15 22:21:48 CET 2011


When using slf4j with log4j, if a configuration is not correctly 
specified, a WARN message is sent to System.err and that is it for 
logging.  You have to do it right.

There are times, though, when I legitimately desire a different 
behavior.  For example, when running (and more importantly, developing) 
JUnit tests.  In this case, I may have an automated test suite that is 
correctly configured on some server, but I might still want to run it 
"quick and dirty" in Eclipse from time to time, without needing to 
specify '-Dlog4j.configuration=blahblah.xml' and see the logging in my 
console.

I would like to be able to say, programmatically, something like

if (Logger.getRootLogger().isNotCorrectlyConfigured()) {
	BasicConfigurator.configure();
}

or something of that nature.  But there appears to be no way to 
programatically detect the condition that triggers that warning and do 
something about it.

Or do I miss something?

Steve Cohen



More information about the slf4j-user mailing list