傻瓜式log4j配置日誌
阿新 • • 發佈:2020-07-20
maven 配置
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.2</version>
</dependency>
log4j.properties
#所有日誌
log4j.rootLogger = DEBUG,stdout,file
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.logger.cn.wdq=DEBUG,wdq
#控制檯輸出
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
#所有檔案輸出
log4j.appender.file = org.apache.log4j.FileAppender
#log4j.appender.file.File = ${webApp.root}/logs/allDEBUG.log
log4j.appender.file.File = src/main/java/logs/allDEBUG.log //