[logback-user] Disable scanning of logback.xml during initialization

Simon Wong simonwg at gmail.com
Thu Apr 17 04:44:39 CEST 2014


  I am using logback with Spring logback extension. The exact log location
is determined at runtime through the "webAppRootKey" context param, that
mentioned in WebLogbackConfigurer

  In web.xml,


  In logback.xml,
    <appender name="FILE"

            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{32} -

  The issue is during logback initialization, it will scan the logback.xml
automatically but the ${myApp.root} is not yet resolved, due to Spring Web
Application Context is initialized lazily. The log entry could not write to
log file successfully.

  The workaround solution is the program "touch" the logback.xml again
during @PostConstruct phase after Spring Web Application Context is
constructed. Logback will scan the change of logback.xml some time later
and at that time the ${myApp.root} is correctly resolved.


    void init() {
        try {
            ClassPathResource logbackResource = new
            File logbackConfigFile = logbackResource.getFile();
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);

   Is there a way that I could disable the auto scanning of logback.xml
during initialization? Or defer
until ch.qos.logback.ext.spring.web.LogbackConfigListener is well
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20140417/05085f52/attachment.html>

More information about the Logback-user mailing list