Saturday 26 February 2022

logback: reload configuration file upon modification

logback has a feature to reload the configuration upon modifications and automatically reconfigure when the configuration file changes.

 

Example

<configuration scan="true"> 
  ... 
</configuration>

 

By setting the ‘scan’ attribute of configuration element, we can enable auto reload feature. By default, the configuration file will be scanned for changes once every minute.

 

Can I customize the scan schedule time?

Yes, by setting ‘scanPeriod’ attribute, you can customize the frequency.

<configuration scan="true" scanPeriod="30 seconds" > 
  ...
</configuration>

 

‘scanPeriod’ value can be specified in the units of milliseconds, seconds, minutes or hours. If you do not specify any unit of time, milliseconds is considered by default.

 

Example
<configuration scan="true" scanPeriod="15 seconds" > 

  <statusListener
    class="ch.qos.logback.core.status.OnConsoleStatusListener" />

  <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="info">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

 

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment