问题描述
我的一个Spring Boot应用程序在其Maven test 阶段出现了问题.
One of my Spring Boot applications makes problems during its Maven test phase.
在测试和常规"应用程序运行期间,Spring Boot应用程序都使用非常类似于 src/main/resources/logback-spring.xml
.该配置文件(以传递方式)包括 base.xml
和 file-appender.xml
.这些配置文件设置了 logback属性 LOG_FILE=/tmp/spring.log
.
Both during testing and "regular" application runtime, the Spring Boot application uses a logback configuration file very similar to src/main/resources/logback-spring.xml
. This configuration file (transitively) includes the logback configuration files base.xml
and file-appender.xml
. These configuration files set a logback property LOG_FILE=/tmp/spring.log
.
我认为最好的做法是文件/tmp/server.log
由用户和组${MY_SPRING_BOOT_APPLICATION}
拥有.
I guess it is best practice that file /tmp/server.log
is owned by user and group ${MY_SPRING_BOOT_APPLICATION}
.
Jenkins以用户jenkins
身份运行. jenkins
没有对/tmp/server.log
的写权限.因此,Jenkins执行JUnit测试时会失败.
Jenkins runs as user jenkins
. jenkins
does not have write permissions for /tmp/server.log
. Therefore the JUnit tests fail when executed by Jenkins.
- 配置日志记录以使其在Jenkins build-with-tests 和期间运行良好的最佳方法是什么,以便设置每日滚动日志记录当使用 Spring Boot的 SysV init.d 服务功能(将日志放入
/var/log/
)? - 如果同时运行两个或多个Spring Boot应用程序,文件
/tmp/spring.log
是否会被同时修改(并因此被破坏)?
- What is the best way to configure logging so that it works well during a Jenkins build-with-tests and so that it sets up daily rolling logging when leveraging Spring Boot's SysV init.d service functionality (which puts logs into
/var/log/
)? - Will file
/tmp/spring.log
be modified (and therefore be broken) concurrently if there are two or more Spring Boot applications running at the same time?
推荐答案
在我的Spring Boot应用程序中,我已将<property name="LOG_TEMP" value="./logs"/>
添加到src/test/resources/logback-test.xml
:
In my Spring Boot application, I have added <property name="LOG_TEMP" value="./logs"/>
to src/test/resources/logback-test.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<property name="LOG_TEMP" value="./logs"/>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="com.example" level="INFO"/>
<root level="WARN">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
这样,在Maven测试期间,将在当前(测试)工作目录中创建一个单独的日志文件.
This way, during Maven testing, a separate logging file will be created in the current (testing) working directory.
Props to welcor for helping out.
这篇关于Spring Boot在测试过程中使用/tmp/spring.log文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!