[logback-user] Programmatic logback Configuration

Ceki Gulcu listid at qos.ch
Tue Nov 6 19:36:10 CET 2007


Chad,

Your code looks good, although the loggerContext.start() call seems superfluous
to me.

Declaration of new loggers should be picker up. Is it possible that the problems 
lies with the contents of the UEF file? I mean what happens when you replace the 
contents of DLF with the contents of UEF?

Could you provide the contents of both files?

Chad La Joie wrote:
> I apologize for being pushy.  Are there others on this list?  Should I 
> be using a different list?
> 
> Chad La Joie wrote:
>> I have an application that ships with two logging configuration files;
>> a default logback.xml file (DLF) included in the application JAR and a 
>> user-editable file (UEF) installed on the filesystem with other 
>> application configuration files.  The DLF is used when the application 
>> is starting but before the code to read in the UEF is executed.
>>
>> My current code for reading in the UEF looks like this:
>>
>> LoggerContext loggerContext = (LoggerContext) 
>> LoggerFactory.getILoggerFactory();
>>
>> loggerContext.shutdownAndReset();
>>
>> JoranConfigurator configurator = new JoranConfigurator();
>>
>> configurator.setContext(loggerContext);
>>
>> configurator.doConfigure(configuration.getInputStream());
>>
>> loggerContext.start();
>>
>> The behavior I'm seeing though is note quite what I expected.  Assume 
>> the DLF contains a console appender and a logger definition for 
>> package "foo".  The behavior I see when the UEF is loaded is:
>>
>>   - Changes to the logger FOO (e.g. changes in the logging level, 
>> addition/removal of appenders, etc.) are picked up and become active.
>>
>>   - Declaration of new appenders are picked up and become active (e.g. 
>> if a new file appender is defined I can see it creating the new log 
>> file).
>>
>>   - Declaration of new loggers are *not* picked up.  If, for example, 
>> a logger "bar" is defined and given the same console appender as "foo" 
>> no output from "bar" is sent to the console.
>>
>> Is this expected behavior?  Is my code wrong (I've tried the same code 
>> without the start() or shutdownAndReset() method calls)?
>>
>> Any help would be appreciated.
>>
> 

-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch



More information about the Logback-user mailing list