我有多个 spring boot 应用程序(X、Y、Z)打包为部署在我的 tomcat 上的 war 文件。我想使用 log4j2 作为我的应用程序的日志记录系统。因此,为了更改 X 的日志记录系统,我在 tomcat 中将 Sping Boot Propery 'logging.config' 值设置为指向/tomcat/apps/X/WEB-INF/classes/log4j2-spring.properties。通过执行此日志记录,X 可以正常工作。
闪回: 如果我们在 application.properties 中指定 logging.config=classpath:log4j2.properties,那么当我们在 Eclipse 中作为 Java 应用程序运行时,日志记录工作。但是,当我们将其作为 WAR 文件部署在 tomcat 上时,日志记录不起作用。 为了让它工作,我必须将 logging.config= {Path-to-myapp}/log4j2.properties 放在 tomcat/bin/setenv.bat 中。
我的问题是,如果我有多个应用程序,那么如何为每个 Spring Boot 应用程序设置 logging.config。
Since logging is initialized before the ApplicationContext is created, it is not possible to control logging from @PropertySources in Spring @Configuration files. The only way to change the logging system or disable it entirely is via System properties.
最佳答案
我认为有一个错误。 log4j2.properties/log4j2-spring.properties 和 log4j2-spring.xml 的行为是不一样的。如果我们使用 log4j2.properties,则应指定 logging.config=classpath:log4j2.properties。另一方面,如果我们使用 log4j2-spring.xml,则无需指定 logging.config。
在我看来,这是一个需要修复的重要错误,以允许多个 Spring Boot 应用程序部署在同一台服务器上。
修复应该在 org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.getCurrentlySupportedConfigLocations()
中支持 log4j2.properties关于spring - tomcat上部署多个Spring Boot App时如何指定logging.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55032013/