springBoot使用slf4j

2333

记录一下

  1. spring-boot-starter 架包下移除默认日志
<!-- exclusions(排除) --> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions>
  1. 引入日志框架依赖
<!-- 抽象层 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.30</version> </dependency> <!-- 实现 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.26</version> </dependency>
  1. 创建 log4j.properties 并且放到资源文件目录 src/main/resources
log4j.rootLogger=DEBUG,stdout,file log4j.additivity.org.apache=true log4j.appender.stdout=org.apache.log4j.ConsoleAppender <!-- 设置日志显示级别 --> log4j.appender.stdout.threshold=INFO log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%-5p %c{1}:%L - %m%n log4j.appender.file=org.apache.log4j.DailyRollingFileAppender log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.DatePattern='.'yyyy-MM-dd-HH-mm log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n log4j.appender.file.Threshold=INFO log4j.appender.file.append=true <!-- 存放日志路径 --> log4j.appender.file.File=/workspaces/logs/foodie-api/iswn.log