未生成/写入日志文件

时间:2015-07-25 22:09:05

标签: java logging log4j2

我以前有这个工作,它会记录到我的C:驱动器上的文件,但尝试使用CATALINA_HOME环境变量将其工作到日志文件夹似乎无法正常工作。

CATALINA_HOME环境变量设置为C:\apache-tomcat\bin,我希望将日志存储在C:\apache-tomcat\logs

我是否对配置文件做了些蠢事?

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Properties>
        <Property name="LOG_DIR">${sys:CATALINA_HOME}../logs</Property>
        <Property name="ARCHIVE">${LOG_DIR}/archive</Property>
        <Property name="PATTERN">%d{dd/MMM/yyyy HH:mm:ss.SSS} [%t] %X{id} %X{username} %-5level %c{36} %l: %msg%n</Property>
    </Properties>
    <Appenders>
        <Console name="CONSOLE" target="SYSTEM_OUT">
            <PatternLayout pattern="${PATTERN}" />
        </Console>
        <RollingFile name="FileAppender" fileName="${LOG_DIR}/application.log"
                     filePattern="${ARCHIVE}/application.log.%d{yyyy-MM-dd-hh-mm}.gz">
            <PatternLayout pattern="${PATTERN}" />
            <TimeBasedTriggeringPolicy />
        </RollingFile>
    </Appenders>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="FileAppender" />
            <AppenderRef ref="CONSOLE" />
        </Root>
        <Logger name="uk.co" level="INFO" additivity="false">
            <appender-ref ref="FileAppender" />
            <appender-ref ref="CONSOLE" />
        </Logger>
    </Loggers>
    <Logger name="org.hibernate" level="INFO" additivity="false">
        <appender-ref ref="FileAppender" />
        <appender-ref ref="CONSOLE" />
    </Logger>
    <Logger name="org.apache" level="INFO" additivity="false">
        <appender-ref ref="FileAppender" />
        <appender-ref ref="CONSOLE" />
    </Logger>
    <Logger name="org.springframework" level="INFO" additivity="false">
        <appender-ref ref="FileAppender" />
        <appender-ref ref="CONSOLE" />
    </Logger>
</Configuration>

1 个答案:

答案 0 :(得分:0)

通过将${sys:CATALINA_HOME}更改为${env:CATALINA_HOME}

来解决问题

还添加了遗漏/感谢RC