在springboot应用程序中,我有一个jar,然后是带有application.properties,applicationContext.xml和log4j ... properties文件的子目录配置.
In a springboot application, I have a single jar, and then a subdirectory config with application.properties, applicationContext.xml, and log4j...properties file.
我正在尝试将log4j配置外部化.通过这种方式将application.properties外部化.
I am trying to externalize the log4j config. The application.properties is externalized this way.
但是,当springboot运行时,它使用jar文件中的log4j配置文件.通过使用-Dlog4j.debug选项,我可以看到log4j首先使用我的外部文件,但是当spring启动时,它将覆盖jar中的log4j设置.
But, when springboot runs it is using the log4j config file from within the jar file. By using the -Dlog4j.debug option I can see that log4j uses my external file first, but when spring starts it overrides the log4j setting with the one in the jar.
这是启动示例(包含所有选项)
here is an example startup (with all options)
java -Dlog4j.debug -Dlogging.config="file:/opt/config/log4j-qa.properties" -Dlog4j.configuration="file:/opt/config/log4j-qa.properties" -jar /opt/myjarName.jar --spring.config.location=/opt/config/在首次启动时出现log4j状态log4j:从URL文件读取配置:/opt/config/log4j-qa.properties
on first startup log4j states log4j: Reading configuration from URL file:/opt/config/log4j-qa.properties
然后在springboot上启动log4j:从URL jar中读取配置:file:/opt/dms-events-api.jar!/log4j-qa.properties
then on springboot start log4j: Reading configuration from URL jar:file:/opt/dms-events-api.jar!/log4j-qa.properties
但是我希望它只读取外部文件:/opt/config/log4j-qa.properties
but I want it to read only the external file file:/opt/config/log4j-qa.properties
推荐答案有两个问题:
用于外部化的配置:-在Spring Boot jar中尝试并在低于1的水平下工作
Configuration for externalise: - Tried and works below one for me in spring boot jar -Dlog4j.configuration=file:/Users/test/Any-Folder/log4j.properties
Spring日志记录接管了-为此,您需要排除日志记录模块.PFB Gradle 构建的配置.
Spring logging takes over - for that you need to exclude the logging module. PFB the config for Gradle build.
configurations { all*.exclude module : 'spring-boot-starter-logging' }
更多推荐
SpringBoot外部化log4j配置
发布评论