A new ReconfigureOnChangeFilter at each reload of the config file

I started playing with Logback yesterday. I use scan="true" because I want an easy way to modify logging without redeploying my webapp. I noticed that each time I modify logback.xml a new ReconfigureOnChangeFilter is created. After 4 modifications and reloading of logback.xml the logback is reloaded 4 times because each new ReconfigureOnChangeFilter scan and reload the config file. Also, the logging work correctly. My message are logged one time (not 5 times). My only concern is that a new ReconfigureOnChangeFilter is created every time the config file is reloaded. What I'm I doing wrong ? The output from debug="true". I made 4 modifications in the config file. 1 modif : changed level of com.lq from DEBUG to WARN 2 modif : changed scan time from 7 to 8 seconds 3 modif : changed scan time from 8 to 9 seconds 4 modif : changed scan time from 9 to 10 seconds http://old.nabble.com/file/p32099960/logback-debug-2.log logback-debug-2.log My logback.xml : <configuration scan="true" scanPeriod="30 seconds" debug="true"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <root level="debug"> <appender-ref ref="STDOUT" /> </root> </configuration> I use a ServletContextListener to initialize Logback because I want a way to change the logging configuration without redeploying my webapp. If you have a better way, I'm open to suggestion : public void contextInitialized(ServletContextEvent sce) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); // the context was probably already configured by default configuration rules lc.reset(); ServletContext servletContext = sce.getServletContext(); configurator.doConfigure(servletContext.getInitParameter(LOGBACK_CONFIG_FILE_PARAMETER)); } catch (JoranException je) { // StatusPrinter will handle this } } -- View this message in context: http://old.nabble.com/A-new-ReconfigureOnChangeFilter-at-each-reload-of-the-... Sent from the Logback User mailing list archive at Nabble.com.

Hello, I am looking into this. By the way, what is the value of LOGBACK_CONFIG_FILE_PARAMETER? -- Ceki On 20.07.2011 21:06, dunand wrote:
I started playing with Logback yesterday. I use scan="true" because I want an easy way to modify logging without redeploying my webapp. I noticed that each time I modify logback.xml a new ReconfigureOnChangeFilter is created. After 4 modifications and reloading of logback.xml the logback is reloaded 4 times because each new ReconfigureOnChangeFilter scan and reload the config file. Also, the logging work correctly. My message are logged one time (not 5 times). My only concern is that a new ReconfigureOnChangeFilter is created every time the config file is reloaded. What I'm I doing wrong ?
The output from debug="true". I made 4 modifications in the config file. 1 modif : changed level of com.lq from DEBUG to WARN 2 modif : changed scan time from 7 to 8 seconds 3 modif : changed scan time from 8 to 9 seconds 4 modif : changed scan time from 9 to 10 seconds http://old.nabble.com/file/p32099960/logback-debug-2.log logback-debug-2.log
My logback.xml : <configuration scan="true" scanPeriod="30 seconds" debug="true"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender>
<root level="debug"> <appender-ref ref="STDOUT" /> </root> </configuration>
I use a ServletContextListener to initialize Logback because I want a way to change the logging configuration without redeploying my webapp. If you have a better way, I'm open to suggestion : public void contextInitialized(ServletContextEvent sce) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); // the context was probably already configured by default configuration rules lc.reset(); ServletContext servletContext = sce.getServletContext();
configurator.doConfigure(servletContext.getInitParameter(LOGBACK_CONFIG_FILE_PARAMETER)); } catch (JoranException je) { // StatusPrinter will handle this } }

Ceki Gulcu wrote:
By the way, what is the value of LOGBACK_CONFIG_FILE_PARAMETER?
I'm using : "C:\tmp\logging\logback.xml" I also tried "\\server\x\y\logback.xml" with the same output. -- View this message in context: http://old.nabble.com/A-new-ReconfigureOnChangeFilter-at-each-reload-of-the-... Sent from the Logback User mailing list archive at Nabble.com.

On 20.07.2011 22:56, dunand wrote:
Ceki Gulcu wrote:
By the way, what is the value of LOGBACK_CONFIG_FILE_PARAMETER?
I'm using : "C:\tmp\logging\logback.xml" I also tried "\\server\x\y\logback.xml" with the same output.
OK. The configuration file is external to your application. You can package logback.xml within your web-app and include C:\tmp\logging\logback.xml from logback.xml: Example logback.xml file: <configuration scan="true"> <include file="C:\tmp\logging\logback.xml"/> </configuration> The included file must list its contents within <included> element. See [1]. The file C:\tmp\logging\logback.xml becomes: <included> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>...</pattern> </encoder> </appender> <root level="debug"> <appender-ref ref="STDOUT" /> </root> <included> With this inclusion trick you no longer need initialization code in ServletContextListener. By the way, another alternative is the logback.configurationFile system property. See [2] for more details. [1] http://logback.qos.ch/manual/configuration.html#fileInclusion [2] http://logback.qos.ch/manual/configuration.html#configFileProperty

Ceki Gulcu wrote:
OK. The configuration file is external to your application. You can package logback.xml within your web-app and include C:\tmp\logging\logback.xml from logback.xml:
I tried this solution and it work perfectly. No need for initialization code now. Also, I dismissed the logback.configurationFile property solution because we have a lot of web-app in the same virtual machine and we want a separate config file for each application. Thanks a lot for your time ! -- View this message in context: http://old.nabble.com/A-new-ReconfigureOnChangeFilter-at-each-reload-of-the-... Sent from the Logback User mailing list archive at Nabble.com.

As indicated in [1], whenever a change is detected, the ReconfigureOnChangeFilter resets the logger context which will have the affect of stopping and removing that ReconfigureOnChangeFilter. A new ReconfigureOnChangeFilter will be created as a result of reloading the configuration file. So there is only one ReconfigureOnChangeFilter active at a time. Here are some relevant lines from [1]: 13:59:57,209 |-INFO in c.q.l.c.turbo.ReconfigureOnChangeFilter@63066306 - Detected change in [[c:\tmp\logging\logback.xml]] 13:59:57,209 |-INFO in c.q.l.c.turbo.ReconfigureOnChangeFilter@63066306 - Will reset and reconfigure context named [bitmole] 13:59:57,224 |-INFO in c.q.l.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeFilter scanning period to 8 seconds 13:59:57,224 |-INFO in c.q.l.c.turbo.ReconfigureOnChangeFilter@f280f28 - Will scan for changes in [[c:\tmp\logging\logback.xml]] every 8 seconds. I hope this helps, -- Ceki [1] http://old.nabble.com/file/p32099960/logback-debug-2.log logback-debug-2.log On 20.07.2011 21:06, dunand wrote:
I started playing with Logback yesterday. I use scan="true" because I want an easy way to modify logging without redeploying my webapp. I noticed that each time I modify logback.xml a new ReconfigureOnChangeFilter is created. After 4 modifications and reloading of logback.xml the logback is reloaded 4 times because each new ReconfigureOnChangeFilter scan and reload the config file. Also, the logging work correctly. My message are logged one time (not 5 times). My only concern is that a new ReconfigureOnChangeFilter is created every time the config file is reloaded. What I'm I doing wrong ?
The output from debug="true". I made 4 modifications in the config file. 1 modif : changed level of com.lq from DEBUG to WARN 2 modif : changed scan time from 7 to 8 seconds 3 modif : changed scan time from 8 to 9 seconds 4 modif : changed scan time from 9 to 10 seconds http://old.nabble.com/file/p32099960/logback-debug-2.log logback-debug-2.log
My logback.xml : <configuration scan="true" scanPeriod="30 seconds" debug="true"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender>
<root level="debug"> <appender-ref ref="STDOUT" /> </root> </configuration>
I use a ServletContextListener to initialize Logback because I want a way to change the logging configuration without redeploying my webapp. If you have a better way, I'm open to suggestion : public void contextInitialized(ServletContextEvent sce) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); // the context was probably already configured by default configuration rules lc.reset(); ServletContext servletContext = sce.getServletContext();
configurator.doConfigure(servletContext.getInitParameter(LOGBACK_CONFIG_FILE_PARAMETER)); } catch (JoranException je) { // StatusPrinter will handle this } }
participants (2)
-
Ceki Gulcu
-
dunand