slf4j + log4j 日志 使用

MrLiar 2020-01-19

1.依赖(这依赖添加了slf4j和log4j)

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.30</version>
</dependency>

2.配置log4j.properties文件,放在resources目录下

log4j.rootLogger=DEBUG,console,dailyFile
log4j.additivity.org.apache=true

#配置参考文章 https://blog.csdn.net/qq_41947226/article/details/79800296

# 控制台(console)
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Threshold=DEBUG
log4j.appender.console.ImmediateFlush=true
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] %m%n

# 定期滚动日志文件(dailyFile)
log4j.appender.dailyFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.dailyFile.Threshold=DEBUG
log4j.appender.dailyFile.ImmediateFlush=true
log4j.appender.dailyFile.Append=true
log4j.appender.dailyFile.File=D:/logs/log.log
log4j.appender.dailyFile.DatePattern=‘.‘yyyy-MM-dd
log4j.appender.dailyFile.layout=org.apache.log4j.PatternLayout
log4j.appender.dailyFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] %m%n

3.使用即可

相关推荐