[logback-user] Externalized Logback configuration for web applications

bjorn rohde jensen bjensen at fastmail.fm
Fri Aug 17 18:06:39 CEST 2012


Hi Perry,

My use case is basically the same as yours, except im deploying wars in 
a tomcat and not in a full jboss et al.

The solution, i came up with is based on logbacks ability to look up 
values in a JNDI directory and to include files based. Basically you 
pack a skeleton logback configuration with your war. This skeleton 
configuration file simply looks up the url for a file containing the 
real configuration using JNDI and then includes it.

I have attached 3 files, i use to do all this magic, in one of my 
projects as an example.

logback.xml is the skeleton configuration file, which goes into the war. 
It contains a maven pom.name reference, since i use maven filtering to 
ensure, the lookup key matches application. I tend to forget updating 
things like that when reusing code etc.

context.xml is a sample context, i use when testing this particular 
webapp in an embedded tomcat. I have no parameters defined in web.xml, 
since i dont want to risk silently falling back to defaults, i prefer to 
go out with a bang.

logback-test.xml is the actual logback configuration to be included. I 
know, its a bad choice of name, since its a logback magic file name.

I discussed the solution with Ceki on this list under the subject 
'configuration through JNDI' and got the seal of approval, and it has 
worked for me without any problems so far.

Yours sincerely,

Bjorn
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logback.xml
Type: text/xml
Size: 228 bytes
Desc: not available
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120817/dcfcceda/attachment.xml>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: context.xml
Type: text/xml
Size: 428 bytes
Desc: not available
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120817/dcfcceda/attachment-0001.xml>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logback-test.xml
Type: text/xml
Size: 799 bytes
Desc: not available
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120817/dcfcceda/attachment-0002.xml>


More information about the Logback-user mailing list