SpringBoot中使用 Log4j
来源:互联网 发布:mac装win10有什么坏处 编辑:程序博客网 时间:2024/05/21 10:18
Spring boot配置log4j输出日志
1. pom.xml文件中配置parent,版本选定[1.2.5.RELEASE]
关于为什么要选这个版本:我尝试使用[1.4.1.RELEASE],但该版本库里没有[spring-boot-starter-log4j.jar],后面要使用这个jar,使用[1.2.5.RELEASE]版本的[spring-boot-starter-log4j.jar]来顶替,一直没有成功。也许是我哪里配置不对,无法可想,只好把parent版本降至[1.2.5.RELEASE]
并不是说一定要用这个版本,有兴趣的可以尝试一下其他版本。
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.5.RELEASE</version> </parent>
2. 删除pom.xml文件中所有对日志jar包的引用
例如下面两个,如果不删除,和后面将要加入的依赖jar包会有冲突,导致日志不能正常输出到文件
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>log4j-over-slf4j</artifactId> </dependency>
3. 排除spring boot对[spring-boot-starter-logging]的依赖,并增加依赖包[spring-boot-starter-log4j.jar]
话说步骤2中不是删除了对[spring-boot-starter-logging]的依赖吗,为什么还要再次排除呢?原因:可以点开[Effective POM]查看,parent中依然有两处对[spring-boot-starter-logging]的依赖。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j</artifactId> </dependency>
4. 增加log4j.properties配置
配置每天输出一个日志文件.
log4j.rootLogger=info,ServerDailyRollingFile,stdoutlog4j.appender.ServerDailyRollingFile=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.ServerDailyRollingFile.DatePattern='.'yyyy-MM-ddlog4j.appender.ServerDailyRollingFile.File=D://test/test.loglog4j.appender.ServerDailyRollingFile.layout=org.apache.log4j.PatternLayoutlog4j.appender.ServerDailyRollingFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p [%c] - %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
今天在项目里面使用 SpringBoot 集成 log4j,具体的操作参考了下面这篇文章。
这里做一个记录。
阅读全文
0 0
- SpringBoot 中使用 Log4j
- SpringBoot 中使用 Log4j
- SpringBoot中使用 Log4j
- SpringBoot使用log4j
- Log4j和Log4j2的区别(SpringBoot中配置使用)
- log4j配置和springboot中Logback配置
- eclipse 使用maven 构建springboot +log4j
- SpringBoot-log4j
- springboot中使用Druid
- SpringBoot中使用redis
- SpringBoot中使用Filter
- SpringBoot 中使用JSP
- springboot中使用RestTemplate
- SpringBoot中使用ElasticJob
- springboot中使用logback
- SpringBoot中使用fastjson
- Springboot中使用缓存
- Springboot中使用定时器
- 大数据晨报:用人工智能伪造奥巴马演讲 阿里巴巴市值超过4000亿
- Generation Warnings Occured Project *** does not exist
- 时序预测,TensorFlow的策略
- codeforces 799C Fountains
- 笔记:继承
- SpringBoot中使用 Log4j
- [USACO2.4]穿越栅栏 Overfencing
- Git 的origin和master分析
- 三层架构
- spring boot 静态变量注入配置文件
- new, operator new 和 placement new
- Windows 下安装Java
- ScrollView嵌套ViewPager空白,上下或者左右不能滑动问题
- 完美拖拽-return false的用法-事件绑定