SpringBoot 中使用 Log4j

来源:互联网 发布:机器人编程指令 编辑:程序博客网 时间:2024/05/21 18:43

SpringBoot 中使用 Log4j 
1、pom 文件中排除 slf4j 的依赖 
说明:如果你是 spring-boot-starter-web 模块的,同样地,也排除掉 slf4j 的依赖,

<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-jersey</artifactId>    <exclusions>        <exclusion>            <artifactId>log4j-over-slf4j</artifactId>            <groupId>org.slf4j</groupId>        </exclusion>    </exclusions></dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

2、引入 log4j 的依赖:

<dependency>    <groupId>log4j</groupId>    <artifactId>log4j</artifactId></dependency>
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

3、自己测试的时候要看到日志起作用了才算。 
log4j.properties 配置文件:

log4j.rootLogger=DEBUG,ServerDailyRollingFile,stdoutlog4j.appender.ServerDailyRollingFile=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.ServerDailyRollingFile.DatePattern='.'yyyy-MM-dd_HHlog4j.appender.ServerDailyRollingFile.File=log4j.loglog4j.appender.ServerDailyRollingFile.layout=org.apache.log4j.PatternLayoutlog4j.appender.ServerDailyRollingFile.layout.ConversionPattern=%d - %m%nlog4j.appender.ServerDailyRollingFile.Append=truelog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d yyyy-MM-dd HH:mm:ss %p [%c] %m%n
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

今天在项目里面使用 SpringBoot 集成 log4j,具体的操作参考了下面这篇文章。 
这里做一个记录。 
http://www.dutycode.com/spring_boot_log4j_shiyong.html

0 0
原创粉丝点击