NutzCN Logo
精华 以前使用log4j,后台可以打印sql日志,现在换成log4j2了,所有日志都不打印了,怎么破
发布于 3008天前 作者 qq_16dd5808 6443 次浏览 复制 上一个帖子 下一个帖子
标签:

以前使用log4j,后台可以打印sql日志,现在换成log4j2了,所有日志都不打印了,怎么破
下面是我log4j2.xml的内容

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Properties>
        <!-- %highlight{ 内容 }{FATAL=bright black, ERROR=bright red, WARN=bright yellow, INFO=blue, DEBUG=bright black, TRACE=bright black} -->
        <Property name="rawPattern">
            %highlight{[%-5level][%d{yyyy-MM-dd HH:mm:ss.SSS}]%l}{FATAL=bright black, ERROR=bright red, WARN=bright yellow, INFO=blue, DEBUG=bright black, TRACE=bright black}%message%n
        </Property>
    </Properties>

    <Appenders>
        <!-- 控制台配置 -->
        <Console name="console"
                 target="SYSTEM_OUT">
            <PatternLayout pattern="${rawPattern}" />
            <ThresholdFilter level="DEBUG" />
        </Console>

        <!-- 每小时一个日志 -->
        <RollingFile name="rollingFile"
                     fileName="../logs/log.log"
                     filePattern="../logs/$${date:yyyy}/$${date:yyyy-MM}/$${date:yyyy-MM-dd}/%d{yyyy-MM-dd_HH}.log">
            <PatternLayout pattern="[%-5level][%d{yyyy-MM-dd HH:mm:ss.SSS}]%l%message%n" />
            <ThresholdFilter level="ALL" />
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"
                                           modulate="true" />
            </Policies>
            <DefaultRolloverStrategy>
                <Delete basePath="../logs/"
                        maxDepth="5">
                    <IfFileName glob="*.log" />
                    <IfLastModified age="30d" />
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>
    </Appenders>

    <Loggers>
        <!-- 日志级别有:OFF、FATAL、ERROR、WARN、INFO、DEBUG、TRACE、ALL -->
        <!-- 同步日志 -->
        <!--<Root level="ALL">
            <AppenderRef ref="console" />
            <AppenderRef ref="rollingFile" />
        </Root>-->
        <!-- 异步日志 -->
        <AsyncRoot level="ALL"
                   includeLocation="true">
            <AppenderRef ref="console" />
            <AppenderRef ref="rollingFile" />
        </AsyncRoot>

    </Loggers>
</Configuration>
7 回复

看本站源码的log4j.xml,地址在页脚.

来自炫酷的 NutzCN

用了你的log4j2.xml,还是没有打印出sql日志,感觉好像是nutz的日志没有交给log4j2去管理似的

@qq_16dd5808 仔细看pom.xml

来自炫酷的 NutzCN

pom.xml也没发现什么问题。下面是我的

<!-- log4j2日志依赖 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.21</version>
        </dependency>
        <!-- log4j2 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.6.2</version>
        </dependency>
        <!-- 用于slf4j与log4j2桥接 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.6.2</version>
        </dependency>
        <!-- commons-logging与log4j2桥接 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-jcl</artifactId>
            <version>2.6.2</version>
        </dependency>
        <!-- 使用log4j2的异步日志需要的依赖 -->
        <dependency>
            <groupId>com.lmax</groupId>
            <artifactId>disruptor</artifactId>
            <version>3.3.5</version>
        </dependency>
        <!-- web工程需要的log4j2 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-web</artifactId>
            <version>2.6.2</version>
        </dependency>

加 log4j-1.2-api

成功。加了

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

就可以了。多谢@wendal
留给后人:
log4j2版本的依赖

<!-- log4j2日志依赖 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.21</version>
        </dependency>
        <!-- log4j2 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.6.2</version>
        </dependency>
        <!-- 用于slf4j与log4j2桥接 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.6.2</version>
        </dependency>
        <!-- commons-logging与log4j2桥接 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-jcl</artifactId>
            <version>2.6.2</version>
        </dependency>
        <!-- 使用log4j2的异步日志需要的依赖 -->
        <dependency>
            <groupId>com.lmax</groupId>
            <artifactId>disruptor</artifactId>
            <version>3.3.5</version>
        </dependency>
        <!-- web工程需要的log4j2 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-web</artifactId>
            <version>2.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-1.2-api</artifactId>
            <version>2.6.2</version>
        </dependency>
添加回复
请先登陆
回到顶部