【问题标题】:spring-boot - External log4j configuration not workingspring-boot - 外部 log4j 配置不起作用
【发布时间】:2017-05-05 05:04:24
【问题描述】:

我正在尝试为生产环境进行设置,所以我想将log4j.properties 保留在我的应用程序 jar 文件之外。

为此,我将application.propertieslog4j.properties 文件与我的spring-boot jar 文件保持平行。我在我的 application.properties 中给出了logging.config: file:log4j.properties。这似乎不起作用。 Spring 仍在拾取放在 jar 文件中的 log4j.properties 文件。

我尝试在logging.config 属性中提供绝对路径,例如C:\Users\furquan\project\jars\log4j.properties,但它仍然是正在使用的 log4j.properties 是 jar 文件中的那个。

请帮忙,很重要!!!

【问题讨论】:

  • 如果没有,则必须放入特定目录:src/main/resources/log4j.properties

标签: spring logging spring-boot log4j properties-file


【解决方案1】:
-Dlogging.config=/path/to/log4j.properties

或者您可以在application.propertiesbootstrap.properties 中指定它。

来自26.5 Custom log configuration

请注意:

在 spring boot 1.4 之后,Log4j 1 支持已被移除。所以也许你可以考虑使用默认的 logback,或者改用 log4j2。

【讨论】:

  • 我需要像-Dlogging.config=file:/path/to/log4j.properties一样指定file:
  • 我也试过了,它似乎不起作用,这就是我试过的:java -jar webService.jar -Dlogging.config=file:C:\Users\furquan\project\deliverable\webservice\log4j.propertiesjava -jar webService.jar -Dlogging.config=C:\Users\furquan\project\deliverable\webservice\log4j.properties
  • 在窗口中。你应该像“C:\\Users\\furquan\\....”一样使用“\\”,或者使用“C:/Users/furquan/....”
  • 春季启动版本?如果还是不行,可以调试org.springframework.boot.logging.LoggingApplicationListener#initializeSystem看看logConfig是否初始化成功。
  • 版本是1.2.0.RELEASE 好的,我会尝试调试它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-17
  • 1970-01-01
  • 2017-11-26
  • 1970-01-01
  • 1970-01-01
  • 2021-08-30
  • 2017-10-08
相关资源
最近更新 更多