英文:
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:
<property name = "logging.path" value = "/logs"/>
<property name = "logging.file" value = "app-logger"/>
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 '<property resource="application.${env}.properties"/>
' to your logback.xml
And finally in your file appender , add '<file>${LOG_DIR}/serive.log</file>
'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论