如何在 UAT 服务器上更改 (logback.xml) 中的 logging.file 路径?

huangapple go评论54阅读模式
英文:

How to change the path for logging.file in (logback.xml) for UAT server?

问题

我正在尝试在UAT(Linux)服务器上运行一个项目,但出现了问题,我需要将日志写入测试服务器的不同路径。

项目资源包含logback.xml,它指定了日志的写入位置:

<property name="logging.path" value="/logs"/>
<property name="logging.file" value="app-logger"/>

我无法更改此文件,因为在这种情况下一切都是正确的,但对于UAT,我创建了另一个logback.xml,并将其放在资源之外的另一个目录中,当我运行jar文件时,我希望指定要使用这个logback.xml。

在UAT上,我执行以下命令:

java -Xmx512M -jar /home/user/app/program/program-0.1.jar --logging.config=app/program/config/logback.xml

我收到了这个错误:

ERROR in ch.qos.logback.core.rolling.RollingFileAppender [RollingFile] - openFile (/logs/app-logger.log,true) call failed. java.io.FileNotFoundException: /logs/app-logger.log (No such file or directory)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration (LogbackLoggingSystem.java:169)

所以我创建的第二个logback.xml 被忽略了,而使用了位于资源中的一个。我做错了什么?如何将另一个logback.xml 放入Spring中?

英文:

I am trying to run a project on a UAT (Linux) server, but there is a problem, I need the logs to be written on the test server in a different path.

The project resources contain logback.xml, which specifies where to write logs:

&lt;property name = &quot;logging.path&quot; value = &quot;/logs&quot;/&gt;
&lt;property name = &quot;logging.file&quot; value = &quot;app-logger&quot;/&gt;

I cannot change this file, because in this case everything is correct, but for UAT I created another logback.xml and put it not in the resources but in another directory, and when I run the jar file I want to specify that I need to take this one logback.xml

On UAT I execute this command

java -Xmx512M -jar /home/user/app/program/program-0.1.jar --logging.config = app/program/config/logback.xml

I got this error:

ERROR in ch.qos.logback.core.rolling.RollingFileAppender [RollingFile] - openFile (/logs/app-logger.log,true) call failed. java.io.FileNotFoundException: /logs/app-logger.log (No such file or directory)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration (LogbackLoggingSystem.java:169)

So the second file logback.xml which I created is ignored and the one that lies in the resources is used. What am I doing wrong? How to put another logback.xml into Spring?

答案1

得分: 1

你可以将所需的日志目录添加到您的环境特定属性文件中,应该类似于application.uat.properties。所以您可以添加类似于 LOG_DIR=path/to/directory 的内容。

完成后,在您的logback.xml中添加 <property resource="application.${env}.properties"/>

最后,在您的文件附加器中,添加 <file>${LOG_DIR}/serive.log</file>

英文:

You can add in your required log directory to your environment specific properties file,
should be something like application.uat.properties. So you would add in something like LOG_DIR=path/to/directory

Once that is done add in '&lt;property resource=&quot;application.${env}.properties&quot;/&gt;' to your logback.xml

And finally in your file appender , add '&lt;file&gt;${LOG_DIR}/serive.log&lt;/file&gt;'

huangapple
  • 本文由 发表于 2020年7月29日 20:52:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63154054.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定