zoukankan      html  css  js  c++  java
  • log4j2+mybaits 打印sql操作语句

    1、log4j2依赖   

    pom.xml
         <!--
    log4j2 日志模块 --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.8.2</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.8.2</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-web</artifactId> <version>2.8.2</version> </dependency>

    2、在resources目录下创建 log4j2.xml文件

    log4j2.xml

    <?
    xml version="1.0" encoding="UTF-8"?> <Configuration status="INFO" monitorInterval="1800"> <appenders> <Console name="consolePrint" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %logger{36} - %msg%n" /> </Console> </appenders> <loggers> <!-- 将业务dao接口填写进去,并用控制台输出即可 --> <logger name="cn.zgmh.zxks.mapper.dao" level="DEBUG" additivity="false"> <appender-ref ref="consolePrint"/> </logger> <root level="info"> <appender-ref ref="consolePrint" /> </root> </loggers> </Configuration>

    3、在web.xml中进行配置

      <!-- log4j2 日志 -->
      <context-param>  
        <param-name>log4jConfiguration</param-name> 
       <param-value>classpath:log4j2.xml</param-value> </context-param> <listener> <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class> </listener>

    4、在mybatis配置文件中 配置

        <settings>
            <!-- 开启驼峰命名 -->
            <setting name="mapUnderscoreToCamelCase" value="true" />
            
            <!-- log4j2日志 -->
            <setting name="logImpl" value="LOG4J2" />
        </settings>

    5、已经配置ok了。可以看下效果了

  • 相关阅读:
    2019 SDN上机第5次作业
    hdu 2553 N皇后问题(递归)
    百练oj 2766 最大子矩阵和
    POJ 1664 放苹果
    POJ 3617 Best Cow Line(贪心)
    HDU 2013 ACM/ICPC Asia Regional Hangzhou Online ------ Zhuge Liang's Mines
    HDU 4712 Hamming Distance (随机算法)
    HDU 1171 Big Event in HDU
    HDU 1085 Holding Bin-Laden Captive!
    HDU 1028 母函数
  • 原文地址:https://www.cnblogs.com/wangchengb/p/9464872.html
Copyright © 2011-2022 走看看