1

Does logback read environment variables during variable substitution? I'm getting REM_HOME_IS_UNDEFINED on the console during app startup. The variable exists though. The manual says that env variables are looked up last in the food chain. http://logback.qos.ch/manual/configuration.html#variableSubstitution

Here's what I'm doing:

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${REM_HOME}/reac/logs/reac.log</file>

    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>${REM_HOME}/reac/logs/archives/reac-%i.log.zip</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>3</maxIndex>
    </rollingPolicy>

    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>5MB</maxFileSize>
    </triggeringPolicy>

    <encoder>
        <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %logger{36} %-5level - %msg%n</pattern>
    </encoder>      
</appender>
Deepak Marur
  • 537
  • 1
  • 13
  • 27

1 Answers1

2

Here's what I ended doing:

I'm reading the env variable and calling System.setProperty to set the value as a system variable and resetting the loggercontext.

System.setProperty(REM_HOME, remHome);

        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

        try {
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(context);

            // Call context.reset() to clear any previous configuration, e.g. default 
            // configuration. For multi-step configuration, omit calling context.reset()
            context.reset(); 
            configurator.doConfigure(getClass().getClassLoader().getResourceAsStream(LOG_CONF_FILE));
        } 
        catch (JoranException je) {
            // StatusPrinter will handle this
            je.printStackTrace();
        }
        StatusPrinter.printInCaseOfErrorsOrWarnings(context);
Deepak Marur
  • 537
  • 1
  • 13
  • 27