• SSM环境下配置log4j输出sql和异常到控制台和本地日志文件中


    1.引入日志依赖包

     1 <!--解决Spring使用slf4j输出日志与log4j冲突的问题-->  
     2 <dependency>  
     3     <groupId>org.slf4j</groupId>  
     4     <artifactId>slf4j-log4j12</artifactId>  
     5     <version>1.6.6</version>  
     6 </dependency>  
     7 <!-- log4j的包 -->
     8 <dependency>  
     9     <groupId>org.slf4j</groupId>  
    10     <artifactId>slf4j-api</artifactId>  
    11     <version>1.6.6</version>  
    12 </dependency>  
    13 <dependency>  
    14     <groupId>log4j</groupId>  
    15     <artifactId>log4j</artifactId>  
    16     <version>1.2.16</version>  
    17 </dependency>  

    2.web.xml中的配置

    <!-- log4j 配置 -->  
    <context-param>
      <param-name>log4jConfigLocation</param-name>
      <param-value>classpath:log4j.properties</param-value>
      <!-- <param-value>/WEB-INF/log4j.xml</param-value> -->
    </context-param>
    <listener>
       <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    3.log4j.properties

    log4j.rootLogger=INFO,Console,File
    
    log4j.appender.CONSOLE= org.apache.log4j.ConsoleAppender  
    log4j.appender.CONSOLE.Target= System.out  
    
    log4j.appender.CONSOLE.layout= org.apache.log4j.PatternLayout  
    log4j.appender.CONSOLE.layout.ConversionPattern = 
    u7EA7u522B:%p
    u4FE1u606F:%m
    u4F4Du7F6E:%l
    u65F6u95F4:%d
    u7C7Bu76EE:%c
    u7EBFu7A0B:%t
      
    
    #cn.bs.nl.mapper映射目录路径
    log4j.logger.cn.bs.nl.mapper=DEBUG
    
    log4j.appender.File=org.apache.log4j.RollingFileAppender
    log4j.appender.File.File=logs/ssm.log
    
    log4j.appender.File.Threshold=ALL
    log4j.appender.File.layout=org.apache.log4j.PatternLayout
    log4j.appender.File.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH:mm|:ss}][%c]%m%n

     参考链接:

    http://blog.csdn.net/github_32658299/article/details/54288923
    
    https://www.cnblogs.com/zyw-205520/p/5416412.html
    
    https://www.cnblogs.com/wangzhuxing/p/7753420.html
  • 相关阅读:
    总复习
    第十七天(最后的模块)
    第十五天(内置函数)
    第16天(内置模块)
    第十四天(模块)
    第十三天(都是理论)
    第十二天(叠加装饰器和迭代器)
    python基础学习-day33==课后作业练习
    python基础学习-面向对象高级
    python基础学习-day29==课后作业练习
  • 原文地址:https://www.cnblogs.com/ccEmma/p/8575031.html
Copyright © 2020-2023  润新知