log4j2怎样配置才能在控制台打印mybatis的sql日志

asia007 发布于 2015/11/16 14:26
阅读 5K+
收藏 0

框架为spring 4.0 mvc+mybatis,现在配置的log4j2可以输出日志,但是sql不打印,请问要怎样配置才能打印sql

log4j2.xml:

<Configuration status="DEBUG">
  <Appenders>
  <Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH🇲🇲ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
    <!-- Async Loggers will auto-flush in batches, so switch off immediateFlush. -->
    <RollingRandomAccessFile name="RandomAccessFile" fileName="d://logs/mylog.log"
    filePattern="d://logs/mylog_%d{yyyy-MM-dd}_%i.log" immediateFlush="false">
      <PatternLayout>
        <Pattern>%d %p %class{1.} [%t] %location %m %ex%n</Pattern>
      </PatternLayout>
      <Policies>
           <TimeBasedTriggeringPolicy modulate="true" interval="24"/>
         <!--    <SizeBasedTriggeringPolicy size="51200 KB"/> -->
       </Policies>
    </RollingRandomAccessFile>
  </Appenders>
  <Loggers>
    <asyncRoot level="info">
      <appender-ref ref="RandomAccessFile"/>
    </asyncRoot>
  </Loggers>
</Configuration>

加载中
0
fyduan
fyduan

在Loggers节点下添加如下内容

<!-- show sql-->

<logger name="你的mybatis mapper接口package路径" level="DEBUG"/>


<root level="DEBUG">
            <appender-ref ref="console" />
        </root>



返回顶部
顶部