编写简单的POC来证明和测试Spring Boot和log4j2的兼容性。一旦成功,我将把它转移到真正的应用程序中。
请参考我的POC源码:https://github.com/Dennyss/SpringBootLog4j2POC
我从以下网址了解/阅读了Spring版本和log4j2兼容性:How to set up Spring Boot and log4j2 properly?
找到并尝试了此处描述的建议:Spring-Boot logging with log4j2?
但还是不起作用。问题是应用程序日志和Spring日志都只能打印到控制台。
请参考下面的maven依赖项(来自POC):
<dependencies>
<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-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>如果我不排除Spring的logback,也不添加boot-starter-log4j2,那么应用程序日志将打印到应用程序文件,但Spring日志根本不会打印。我感觉到了依赖关系的问题。感谢任何人的帮助。
发布于 2017-07-15 07:35:05
根据Spring Boot Logging文档,可以使用logging.config属性指定日志配置文件的位置。我注意到您的start.sh脚本正在传递-Dlog4j.configurationFile。通常,这对于直接集成Spring Boot 2已经足够了,但是Spring Boot使用logging.config。
切换到此选项后,它将写入日志文件:
java -Dlogging.config=/share/LogPOC/log4j2.xml -cp poc.jar:libs/* com.poc.logger.Applicationhttps://stackoverflow.com/questions/45112329
复制相似问题