[logback-user] How to use different xml settings file for logback depending on run.mode
ceki at qos.ch
Thu Sep 20 22:39:28 CEST 2012
I can think of three techniques at your disposal. Moreover, they may be
combined if necessary.
1) conditional processing of config files
This option requires the Janino library. You would have a single config
file parts of which would be activated depending on the value of the
2) file inclusion
The included file would be a system property, say "includedFile". You
would be responsible for setting "includedFile". Here is a sample
other configuration directives common to various modes go here...
The above uses default values for variables.
3) Specifying the location of the default configuration file as a system
This third option is probably the simplest. You programmatically set the
"logback.configurationFile" system property to point to the
appropriate config file.
BYW, you can reset any existing configuration by invoking:
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
Let us know how it goes.
On 20.09.2012 20:58, Olek Swirski wrote:
> I'm using logback in a runnable jar containing a lift webapp. logback reads
> its settings from logback.xml file at the root of the jar.
> This runnable jar can be run in development mode by just using:
> java -jar myexecutable.jar
> but also in production mode:
> java -Drun.mode=production -jar myexecutable.jar
> I would like to be able to use different file for logback configuration
> depending on
> the run.mode. For example in default (development) mode this could be
> default.logback.xml (or just logback.xml as it is by default)
> and in production
> or in test
> How do I do that? In my app, there is a runnable object Start, with main
> where I probably could set some init options for logback depending on
> the run mode,
> which can be detected with System.getProperty("run.mode").
> Here is the topic on lift mailing list, about this executable jar, and
> some last few
> messages are about trying to figure this out
More information about the Logback-user