欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

maven、spring boot 中log4j配置文件的应用

程序员文章站 2022-04-19 23:09:34
...

1.添加log4j相应jar包:

<!-- 日志文件管理包 --> 
    <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>

2.配置log4j.properties文件

log4j.rootLogger=INFO,stdout
# Log everything. Good for troubleshooting
log4j.logger.org.hibernate=INFO
# Log all JDBC parameters
log4j.logger.org.hibernate.type=ALL


log4j.logger.log4jdbc.debug=ERROR
log4j.logger.com.gk.mapper=ERROR

log4j.logger.jdbc.audit=ERROR
log4j.logger.jdbc.resultset=ERROR

log4j.logger.jdbc.sqlonly=DEBUG
log4j.logger.jdbc.sqltiming=ERROR
log4j.logger.jdbc.connection=FATAL

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %5p %c{1}:%L - %m%n

3.在application.properties中声明log4j.properties.

logging.config=classpath:log4j.properties

log4j.properties 中相关知识点

请参考:https://www.cnblogs.com/ITEagle/archive/2010/04/23/1718365.html