Failed to check log

I am having trouble working with the automatic logback scan feature. It seems like he is not picking up the change. I added debug = "true" to the section and after reading its output, everything seems fine. It clearly states that the logback.xml file is monitored for changes every 30 seconds. I do not understand why the changes are not going to. Just find some recommendations on how I can fix this problem further. Thanks.

I should mention that logback is written to the file just fine, the log configuration file just hasn't changed.

logback.xml file

<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="30 seconds" debug="true"> <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> <property name="LOGS_PATH" value="C:\\Users\\****\\Desktop\\css_dev\\q_logs" /> <appender name="scheduledTasksAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${LOGS_PATH}/scheduledTasks.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> <fileNamePattern>${LOGS_PATH}/scheduledTasks.%i.log.zip</fileNamePattern> <minIndex>1</minIndex> <maxIndex>25</maxIndex> </rollingPolicy> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <maxFileSize>5MB</maxFileSize> </triggeringPolicy> <encoder> <pattern>%d{MMM/dd/yyyy HH:mm:ss} %-5level %logger{50} - %msg%n</pattern> </encoder> </appender> <logger name="tasks" level="warn" additivity="false"> <appender-ref ref="scheduledTasksAppender"/> </logger> </configuration> 

Logging to Tomcat when starting a web application:

 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy] |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml] |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/Users/*****/Desktop/css_dev/ProjectQ/build/web/WEB-INF/classes/logback.xml] |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeFilter scanning period to 30 seconds |-INFO in ReconfigureOnChangeFilter{invocationCounter=0} - Will scan for changes in [[C:\Users\*****\Desktop\css_dev\ProjectQ\build\web\WEB-INF\classes\logback.xml]] every 30 seconds. |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Adding ReconfigureOnChangeFilter as a turbo filter |-INFO in ch.qos.logback.core.joran.action.StatusListenerAction - Added status listener of type [ch.qos.logback.core.status.OnConsoleStatusListener] |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy] |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml] |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/Users/*****/Desktop/css_dev/ProjectQ/build/web/WEB-INF/classes/logback.xml] |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeFilter scanning period to 30 seconds |-INFO in ReconfigureOnChangeFilter{invocationCounter=0} - Will scan for changes in [[C:\Users\*****\Desktop\css_dev\ProjectQ\build\web\WEB-INF\classes\logback.xml]] every 30 seconds. |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Adding ReconfigureOnChangeFilter as a turbo filter |-INFO in ch.qos.logback.core.joran.action.StatusListenerAction - Added status listener of type [ch.qos.logback.core.status.OnConsoleStatusListener] |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [scheduledTasksAppender] |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [scheduledTasksAppender] |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@298f464e - Will use zip compression |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@298f464e - Will use zip compression |-WARN in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@298f464e - Large window sizes are not allowed. |-WARN in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@298f464e - Large window sizes are not allowed. |-WARN in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@298f464e - MaxIndex reduced to 21 |-WARN in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@298f464e - MaxIndex reduced to 21 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[scheduledTasksAppender] - Active log file name: C:\Users\*****\Desktop\css_dev\q_logs/scheduledTasks.log |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[scheduledTasksAppender] - Active log file name: C:\Users\*****\Desktop\css_dev\q_logs/scheduledTasks.log |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[scheduledTasksAppender] - File property is set to [C:\Users\*****\Desktop\css_dev\q_logs/scheduledTasks.log] |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[scheduledTasksAppender] - File property is set to [C:\Users\*****\Desktop\css_dev\q_logs/scheduledTasks.log] |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [tasks] to WARN |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [tasks] to WARN |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [tasks] to false |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [tasks] to false |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [scheduledTasksAppender] to Logger[tasks] |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [scheduledTasksAppender] to Logger[tasks] |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@5b63e18f - Registering current configuration as safe fallback point |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@5b63e18f - Registering current configuration as safe fallback point 
+7
source share
5 answers

Update (May 2019): the error seems to be fixed.

=================================================== =============================

As of logback 1.1.7, scanPeriod should be explicitly mentioned. Otherwise, logging in will not scan for changes. This is due to a recent error ( here is the link).

+8
source

The scan really works, but the scan is done in the logback.xml file in the target / build directory, which is not very useful ...

+3
source

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.

+3
source

You specified logback.xml correctly.

This behavior is indicated in the manual: http://logback.qos.ch/manual/configuration.html#autoScan ,

Given that ReconfigureOnChangeFilter is called every time any logger is called, regardless of the level of the logger, ReconfigureOnChangeFilter is absolutely critical in performance. So much so that actually checking whether the scanning period has passed or not is too expensive in itself. To improve performance, the ReconfigureOnChangeFilter is actually "alive" only once every N registration operations. Depending on how often your applications are registered, the value of N can be changed "on the fly" according to the protocol. By default, N is 16, although it can reach 2 ^ 16 (= 65536) for applications with an intensive processor.

In short, when the configuration file changes, it will be automatically reloaded, but only after a few log calls and after a delay determined by the scan period.

Just try recording a few more messages and see if the configuration is loaded correctly.

I hope this helps you.

Respectfully,

Miguel

+1
source

In logback 1.2.3, rescanning the configuration file also seems to fail if the file path contains + . For example, this works:

-Dlogback.configurationFile=etc/logback.xml

until it works

-Dlogback.configurationFile=etc+/logback.xml

Logback manages to load logback.xml during initialization; it is just a reboot that does not work in the latter case. If + does not work, it is possible that other characters are also problematic.

I decided to report an error, but the JIRA instance associated with https://logback.qos.ch/bugreport.html does not seem to be working at the moment.

0
source

Source: https://habr.com/ru/post/1213366/


All Articles