SpringBoot外部化log4j配置

编程入门 行业动态 更新时间:2024-10-14 22:15:55
本文介绍了SpringBoot外部化log4j配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在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配置

    本文发布于:2023-11-25 20:42:38,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1631278.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:SpringBoot   log4j

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!