I ran into a similar problem, and the root cause was how I initialized the log.
Initial setup - does not work:
Below is the code that I used to configure the log using Joran.
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); InputStream is = new FileInputStream(logConfigPath); // 'logConfigPath' is String path of logback.xml. configurator.doConfigure(is);
In addition, my xml log looked like this:
<configuration scan="true" scanPeriod="60 seconds"> .... </configuration>
Somehow, it was not a rescan of my changes to logback.xml.
Troubleshooting
So, I turned on debug mode in the logback.xml file by adding the debug attribute as shown below.
<configuration scan="true" scanPeriod="60 seconds" debug="true"> .... </configuration>
When I started the application again, I noticed a log statement that indicated the root cause of the problem.
12: 23: 58,462 | -WARN in ch.qos.logback.classic.joran.action.ConfigurationAction - Due to the missing top-level configuration file, reconfiguration upon change (scanning configuration files) cannot be performed.
This log is logged by ConfigurationAction.java when it cannot find the mainURL property in ConfigurationWatchList .
Reconfigured - Scanning works like a charm
So, I changed the code where I set up logback through JoranConfigurator . Instead of sending an InputStream as a parameter to configurator.doConfigure(is) I used the overloaded doConfigure method, which itself uses the file path. The updated code looked like this:
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); configurator.doConfigure(logConfigPath);// 'logConfigPath' is String path of logback.xml.
Debug log updated:
12: 35: 37,173 | -INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - scans for changes in [file: / E: /Samples/config/logback.xml]
12: 35: 37173 | -INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Configure ReconfigureOnChangeTask scan period up to 60 seconds
Here it is! Hurrah:)
EDIT:
Considering the GenericConfigurator class, it turns out that mainURL registered in ConfigurationWatchList if we use the doConfigure() method, which takes a URL , String or File as a parameter.
The other three method overloads (with InputStream , InputSource or List<SaxEvent> ) do not register it.