Java 日志记录:在Spring引导中使用Log4j2.properties文件实现Log4j2
如果我指定 'logging.config=src/main/resources/log4j2.properties' 在my application.properties文件中 在spring boot自动检测log4j2.properties并且不需要在application.properties文件中指定“logging.config=src/main/resources/log4j2.properties”的情况下,是否还有其他解决方法 Spring Boot会自动检测类路径中的log4j2.xml、log4j2.json文件,但在我的例子中,log4j2.properties文件不会检测 my pom.xml:Java 日志记录:在Spring引导中使用Log4j2.properties文件实现Log4j2,java,spring-boot,log4j2,Java,Spring Boot,Log4j2,如果我指定 'logging.config=src/main/resources/log4j2.properties' 在my application.properties文件中 在spring boot自动检测log4j2.properties并且不需要在application.properties文件中指定“logging.config=src/main/resources/log4j2.properties”的情况下,是否还有其他解决方法 Spring Boot会自动检测类路径中的log4
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</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>
注意:我使用的Spring引导版本是2.1.3.0版本
参考:也可以使用这种方式:
java -Dlog4j.configurationFile=log4j2.xml -jar xxxx-app.jar
参考:
我不知道Spring Boot会修改Log4j 2用于定位配置文件的逻辑。事实上,我一直在开发一个使用log4j2.yml的Spring引导服务。我用log4j2.properties替换了它,它工作得很好。Log4j的正常发现过程在类路径上找到它
实际上,我很惊讶将logging.config=src/main/resources/log4j2.properties指定为一个Spring启动jar,而它通常不包含src目录。我认为不需要特殊配置。您可以在此处找到使用属性文件配置log4j2的maven示例:
java -Dlog4j.configurationFile=log4j2.xml -jar xxxx-app.jar