невозможно прочитать переменные env в logback - PullRequest
1 голос
/ 01 марта 2012

Считывает ли logback переменные среды во время подстановки переменных? Я получаю REM_HOME_IS_UNDEFINED на консоли во время запуска приложения. Переменная существует, хотя. В руководстве говорится, что переменные env ищутся последними в пищевой цепочке. http://logback.qos.ch/manual/configuration.html#variableSubstitution

Вот что я делаю:

<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>

1 Ответ

2 голосов
/ 05 марта 2012

Вот что я закончил:

Я читаю переменную env и вызываю System.setProperty, чтобы установить значение в качестве системной переменной, и сбрасываю 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);
...