[logback-dev] [JIRA] Created: (LBCLASSIC-202) ServletContextListener to relocate logback config, implementation provided
Attila Király (JIRA)
noreply-jira at qos.ch
Sun Apr 11 18:18:16 CEST 2010
ServletContextListener to relocate logback config, implementation provided
--------------------------------------------------------------------------
Key: LBCLASSIC-202
URL: http://jira.qos.ch/browse/LBCLASSIC-202
Project: logback-classic
Issue Type: New Feature
Affects Versions: 0.9.20
Reporter: Attila Király
Assignee: Logback dev list
In spring there is a Log4jConfigListener which can be used to reconfigure the default location of the log4j config. I always liked to use it because so I could relocate my log4j.xml from the classes directory next to the web.xml so the config files were at one place. Because I did not find something like that I wrote one for logback. I think it could be included into logback-classic.
ch.qos.logback.classic.servlet.LogbackConfigListener configuration is very easy:
1. Add the listener to the web.xml (it should be the first listener so logback gets configured before the other listeners start up):
<listener>
<listener-class>ch.qos.logback.classic.servlet.LogbackConfigListener</listener-class>
</listener>
2. Add a context-param to web.xml to specify the location of the logback config:
<context-param>
<param-name>logbackConfigLocation</param-name>
<param-value>/WEB-INF/log.xml</param-value>
</context-param>
And thats it. The location is resolved in the following way (similar to spring aproach):
- if the location starts with "/" it is resolved as servlet context resource
- otherwise an URL is constructed from it. So you can use locations like this also: file:/foo/bar/logback.xml or file:d:/foo/bar/logback.xml
- if the the first method fails a java.io.FileInputStream is created from the location to be used as input for logback configuration.
- If none of the above worked an error is logged to servlet log but no exception is thrown.
The location can contain system properties, those gets resolved. So a location can be configured for example to: file:${user.home}/configuration/log.xml
The original spring listener only worked with expanded wars this logback variant does not have this requirement.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the logback-dev
mailing list