Spring Boot在测试过程中使用/tmp/spring.log文件 [英] Spring Boot uses /tmp/spring.log file during testing

查看:811
本文介绍了Spring Boot在测试过程中使用/tmp/spring.log文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个Spring Boot应用程序在其Maven test 阶段出现了问题.

One of my Spring Boot applications makes problems during its Maven test phase.

在测试和常规"应用程序运行期间,Spring Boot应用程序都使用非常类似于

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.

  • 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.

welcor 提供帮助的道具.

Props to welcor for helping out.

这篇关于Spring Boot在测试过程中使用/tmp/spring.log文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆