Springboot项目Log4j的使用

maven依赖

 1         <!--log4j-->
 2         <dependency>
 3             <groupId>org.springframework.boot</groupId>
 4             <artifactId>spring-boot-starter</artifactId>
 5             <exclusions>
 6                 <exclusion>
 7                     <groupId>org.springframework.boot</groupId>
 8                     <artifactId>spring-boot-starter-logging</artifactId>
 9                 </exclusion>
10             </exclusions>
11         </dependency>
12         <dependency>
13             <groupId>org.springframework.boot</groupId>
14             <artifactId>spring-boot-starter-log4j</artifactId>
15             <version>1.3.8.RELEASE</version>
16         </dependency>

log4j.properties文件

 1 ### set log levels ###
 2 log4j.rootLogger=info , error , D , E
 3 ### 输出到控制台 ###
 4 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 5 log4j.appender.stdout.Target=System.out
 6 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 7 log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
 8 ### 输出到日志文件 ###
 9 log4j.appender.D=org.apache.log4j.DailyRollingFileAppender
10 log4j.appender.D.File=C://logs/log111.log
11 log4j.appender.D.Append=true
12 log4j.appender.D.Threshold=DEBUG
13 log4j.appender.D.layout=org.apache.log4j.PatternLayout
14 log4j.appender.D.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
15 ### 保存异常信息到单独文件 ###
16 log4j.appender.E=org.apache.log4j.DailyRollingFileAppender
17 log4j.appender.E.File=C://logs/log112.log
18 log4j.appender.E.Append=true
19 log4j.appender.E.Threshold=ERROR
20 log4j.appender.E.layout=org.apache.log4j.PatternLayout
21 log4j.appender.E.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n

使用

 1 private static Logger logger = Logger.getLogger(UserLoginController.class); 

 

  1 logger.info(userList); 

 

 访问

 

posted @ 2022-01-09 11:55  勤快的懒羊羊  阅读(565)  评论(0编辑  收藏  举报