zoukankan      html  css  js  c++  java
  • Log4j配置spring+druid打印日志

    druid

    spring.xml

     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"  init-method="init" destroy-method="close">
            <property name="driverClassName" value="${db.driver}"/>
            <property name="url" value="${db.url}"/>
            <property name="username" value="${db.username}"/>
            <property name="password" value="${db.password}"/>
    
            <property name="initialSize" value="5"/>
            <property name="maxActive" value="20"/>
    
            <!-- 开启Druid的监控统计功能 -->
            <!-- 注意如果要用log4j一定要加上log4j -->
            <property name="filters" value="stat,log4j" />
        </bean>

    log4j.properties加

    # Druid
    log4j.logger.druid.sql=DEBUG
    log4j.logger.druid.sql.DataSource=warn
    log4j.logger.druid.sql.Connection=warn
    log4j.logger.druid.sql.Statement=DEBUG
    log4j.logger.druid.sql.ResultSet=warn

    Spring

    依赖

    <!-- log start -->
        <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>${log4j.version}</version>
        </dependency>
    
        <!-- 这个是对的,需要 -->
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
          <version>1.7.2</version>
        </dependency>
        <!-- 这个是错的,不需要 -->
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-nop</artifactId>
          <version>1.7.9</version>
        </dependency>
    
        <!-- log end -->

    log4j.properties加

    log4j.logger.org.springframework= warn

    我的完整配置

    log4j.rootLogger = DEBUG, stdout
    
    log4j.logger.org.apache.ibatis=warn
    log4j.logger.java.sql=warn
    log4j.logger.org.springframework= warn
    
    # Druid
    log4j.logger.druid.sql=DEBUG
    log4j.logger.druid.sql.DataSource=warn
    log4j.logger.druid.sql.Connection=warn
    log4j.logger.druid.sql.Statement=DEBUG
    log4j.logger.druid.sql.ResultSet=warn
    
    
    log4j.appender.stdout           = org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.Target    = System.out
    log4j.appender.stdout.Threshold = DEBUG
    log4j.appender.stdout.layout    = org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern =  %-d{yyyy-MM-dd HH:mm:ss}  [ %p ]  %m%n
    
    
  • 相关阅读:
    ELK+Kafka集群日志分析系统
    Centos 6.5 部署 redmine 3.3
    Centos 6.5 搭建l2tp 服务端和客户端
    Logstash之multiline 插件
    MYSQL MHA
    windows上给yii2安装插件
    YII2框架的安装
    Apache服务器配置项和虚拟机配置
    浮点数的比较
    微信自定义菜单总结
  • 原文地址:https://www.cnblogs.com/A-yes/p/9894165.html
Copyright © 2011-2022 走看看