log4j2 - 看不到spring日志

时间:2018-03-08 19:40:42

标签: spring log4j2

我有一个j2ee应用程序,我无法在日志文件中看到Spring日志 日志文件在Appender中定义:

<RollingFile name="MyRollingFile"

在磁盘上创建文件,我能够正常查看我的应用程序类日志消息

<Logger name="com.xerox.app" level="debug" additivity="false">
   <AppenderRef ref="MyRollingFile"/>
</Logger>

the HTML log produced

以下是我的pom.xml中的日志依赖项

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.1</version>
    </dependency>

这是log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
    <Properties>
        <Property name="fileName">C:/appLogs/log/LogViewer.html</Property>
        <Property name="fileNamePattern">C:/appLogs/log/LogViewer%d{dd-MM-yyyy}-%i.html</Property>
        <Property name="logPattern">%d{dd-MM-yyyy HH:mm:ss,SSS} [%t] %-5p %c - %m%n</Property>
    </Properties>
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="${logPattern}"/>
        </Console>

        <RollingFile name="MyRollingFile" fileName="${fileName}" filePattern="${fileNamePattern}">
            <HTMLLayout charset="UTF-8"  pattern="${logPattern}"/>
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="10MB"/>
            </Policies>
            <DefaultRolloverStrategy max="10"/>
        </RollingFile>
    </Appenders>
    <Loggers>
        <Logger name="com.xerox.app" level="debug" additivity="false">
            <AppenderRef ref="MyRollingFile"/>
        </Logger>
        <Logger name="org.springframework" level="DEBUG" additivity="false">           
            <AppenderRef ref="Console"/>
            <AppenderRef ref="MyRollingFile"/>
        </Logger>
        <Root level="DEBUG">
            <AppenderRef ref="MyRollingFile"/>
        </Root>
    </Loggers>
</Configuration>

我还尝试将Logger名称更改为:

 logging.level.org.springframework.web

没有成功......

1 个答案:

答案 0 :(得分:1)

您是否尝试过添加log4j2网桥罐? Spring使用org.apache.commons.logging

请参阅 https://logging.apache.org/log4j/2.x/faq.html#which_jars 选择合适的桥罐。