Log4j配置spring+druid打印日志

druid

spring.xml

 "dataSource" class="com.alibaba.druid.pool.DruidDataSource"  init-method="init" destroy-method="close">
        "driverClassName" value="${db.driver}"/>
        "url" value="${db.url}"/>
        "username" value="${db.username}"/>
        "password" value="${db.password}"/>

        "initialSize" value="5"/>
        "maxActive" value="20"/>

        
        
        "filters" value="stat,log4j" />
    

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

依赖


    <dependency>
      <groupId>log4jgroupId>
      <artifactId>log4jartifactId>
      <version>${log4j.version}version>
    dependency>

    
    <dependency>
      <groupId>org.slf4jgroupId>
      <artifactId>slf4j-log4j12artifactId>
      <version>1.7.2version>
    dependency>
    
    <dependency>
      <groupId>org.slf4jgroupId>
      <artifactId>slf4j-nopartifactId>
      <version>1.7.9version>
    dependency>

    

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

转载于:https://www.cnblogs.com/A-yes/p/9894165.html

你可能感兴趣的:(Log4j配置spring+druid打印日志)