zoukankan      html  css  js  c++  java
  • Spring mvc+mybatis+Log4j控制台打印sql语句

    第一步:添加依赖,在web层中

    <!-- log start -->
    <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>${log4j.version}</version>
    </dependency>
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
    </dependency>
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>${slf4j.version}</version>
    </dependency>
    <!-- log end -->

    <slf4j.version>1.6.6</slf4j.version>
    <log4j.version>1.2.12</log4j.version>


    第二步:在resources下添加log4j文件,此文件系统自动加载。

    第三步:

    log4j.properties中添加以下内容
    # Set root category priority to INFO and its only appender to CONSOLE.
    #log4j.rootCategory=INFO, CONSOLE debug info warn error fatal
    log4j.rootCategory=debug, CONSOLE, LOGFILE

    # Set the enterprise logger category to FATAL and its only appender to CONSOLE.
    log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE

    # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
    log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
    log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
    log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m

    # LOGFILE is set to be a File appender using a PatternLayout.
    # log4j.appender.LOGFILE=org.apache.log4j.FileAppender
    # log4j.appender.LOGFILE.File=d:axis.log
    # log4j.appender.LOGFILE.Append=true
    # log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
    # log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m
    # 打印出sql语句相关日志
    log4j.logger.java.sql.ResultSet=error
    log4j.logger.java.sql.Connection=error
    log4j.logger.java.sql.Statement=debug
    log4j.logger.java.sql.PreparedStatement=debug



    如果要在dubbox等分布式项目中打印出来sql,则需要将log4j.properties放入dao或者service中加载,因为在网络中传输过程中,可能导致打印信息传输失败,分页插件使用也要在service中使用,原理同理。
  • 相关阅读:
    javascript 显示类型转换
    javascript 隐式类型转换
    inline/inline-block/block 的区别
    javascript 类型检测
    title与h1的区别、b与strong的区别、i与em的区别?
    CSS定位方式有哪些?position属性的值有哪些?他们之间的区别是什么?
    列出display的值,说明他们的作用。position的值, relative和 absolute定位原点是?
    语义化的理解
    src与href的区别
    img的alt和title的异同?
  • 原文地址:https://www.cnblogs.com/xiaofengshan/p/12823472.html
Copyright © 2011-2022 走看看