Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1309

No autoscaning for logback.xml when using http-URI for config file

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • 1.5.12
    • 1.1.11
    • logback-core
    • None
    • MacOS, Spring Boot 1.5.3.RELEASE, Java 8

    Description

      Here is my logback.xml:

      <configuration scan="true" scanPeriod="10 seconds">
      <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
      <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
       <pattern>
        %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
       </pattern>
       </encoder>
       </appender>
       <logger name="com.acme" level="DEBUG" additivity="false">
        <appender-ref ref="STDOUT"/>
       </logger>
       <root level="INFO">
        <appender-ref ref="STDOUT"/>
       </root>
      </configuration>

      Notice that scan=true and scanPeriod=10 seconds.

      I host my logback.xml file on a remote server and I use Spring Boot to instantiate logback. Spring boot takes the property -Dlogging.config=http://acme.com:1337/logback.xml and passes this to: ch.qos.logback.core.joran.GenericConfigurator#doConfigure(java.net.URL)

      Logback looks up the config-file from the remote url, instantiates the config, and everything seems fine, except for autoscanning.

      I see that logback uses the class ch.qos.logback.core.joran.spi.ConfigurationWatchList to keep track of files with autoscanning and a class called ch.qos.logback.classic.joran.ReconfigureOnChangeTask to do the periodic polling.

      When a URI is added to the watch-list, the following code is executed:

      ch.qos.logback.core.joran.spi.ConfigurationWatchList#addAsFileToWatch
      private void addAsFileToWatch(URL url) {
          File file = convertToFile(url);
          if (file != null) {
              fileWatchList.add(file);
              lastModifiedList.add(file.lastModified());
          }
      }
      
      ch.qos.logback.core.joran.spi.ConfigurationWatchList#convertToFile
      File convertToFile(URL url) {
          String protocol = url.getProtocol();
          if ("file".equals(protocol)) {
              return new File(URLDecoder.decode(url.getFile()));
          } else {
              addInfo("URL [" + url + "] is not of type file");
              return null;
          }
      }
      
      
      

      Notice that theres a check to ensure that the URL-protocol is "file". This check fails for URL's with http-protocol, so no autoscanning is performed on the configuration-file.

      Is this expected behaviour? If so, why, and is it possible to create a feature-request for autoscanning on http-uri's?

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            jorgen.ringen Jørgen Ringen
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: