[logback-user] Logback file is empty

Charalambides, Chryssanthi Chryssa.Charalambides at wsp.com
Wed Aug 22 22:41:02 CEST 2018


Hello all,

I am trying to figure out why logback is not writing to a file. It creates the file okay, but it is not writing anything to it.

I have the following programmatic configuration in my java code. This just reads a properties file and sets system properties out of the logback values so they can be read from the configuration.xml file. It also configures the logger from logback_configuration.xml instead of the default logback.xml

    private static void initLogback() {
        Map<String,String> logbackProperties = new HashMap<>();

        PropertyDeluxe properties = RenoProperties.getProperties();
        for (String key : properties.getKeys())
           if (key.startsWith(RenoProperties.LOGBACK_PROPERTY_PREFIX))
                logbackProperties.put(key,properties.getString(key));

        //set system properties out of the logback values so we can reference them from the configuration file
        for (String key : logbackProperties.keySet())
            System.setProperty(key,logbackProperties.get(key));

        //configure the logger from the logback_configuration.xml. Default is logback.xml
        LoggerContext lc = new LoggerContext();
        try {
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(lc);
            lc.reset();
            configurator.doConfigure(properties.getString(RenoProperties.LOGBACK_CONFIG_FILE_PROPERTY));
        } catch (JoranException je) {
            je.printStackTrace();
        }
        StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
    }


Here are the values defined in the property file. Where base.dir is passed in through the command line as "@@base.dir=C:/project_work/reno"

@@scenario.dir = base.dir/scenarios/scenario.name
@@_outputs.dir = scenario.dir/outputs

logback.config.file = base.dir/resource/code/java/logback_configuration.xml
logback.file.main = _outputs.dir/logs/java_main.log
logback.level = info



And here is the logback_configuration.xml

<configuration scan="true" debug="true">

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
                <file>${logback.file.main}</file>
    <append>true</append>

    <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
      <Pattern>
        %d{HH:mm:ss} [%-30.-30thread] %-5level %-25.25logger{25} - %msg%n
      </Pattern>
    </encoder>
  </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
     <pattern>
        %d{HH:mm:ss} %green([%-5.-5thread]) %-5level %-25.25logger{25} - %msg%n
      </pattern>
    </encoder>
  </appender>

  <root level="${logback.level}">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
  </root>
</configuration>


I’ve looked everywhere and nothing really stands out.  Can anyone see what I’ve missed?

Thank you
Chryssa

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20180822/31152fad/attachment.html>


More information about the logback-user mailing list