Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot uses /tmp/spring.log file during testing

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

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.

I guess it is best practice that file /tmp/server.log is owned by user and group ${MY_SPRING_BOOT_APPLICATION}.

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?
like image 411
Abdull Avatar asked Jun 28 '16 16:06

Abdull


People also ask

How are spring boot logs stored?

To make Spring Boot write its log to disk, set the path and filename. With this configuration, Spring Boot will write to the console and also to a log file called spring. log , at the path you specify.

Which is the default logging file in Springboot?

By default, Spring Boot will only log to the console and will not write log files. If you want to write log files in addition to the console output you need to set a logging. file or logging. path property (for example in your application.

Which logger does spring boot use?

Spring Boot uses Apache Commons logging for all internal logging. Spring Boot's default configurations provides a support for the use of Java Util Logging, Log4j2, and Logback.

Why do we need spring boot logging?

Spring boot allows us to see the logs in the console even if we do not provide any specific configuration for it. This is because spring boot uses Logback for its default logging. Spring boot's internal logging provider is Apache Commons which provides support for Java Util Logging ,Log4j2, and Logback.


1 Answers

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>

This way, during Maven testing, a separate logging file will be created in the current (testing) working directory.

Props to welcor for helping out.

like image 84
Abdull Avatar answered Sep 16 '22 22:09

Abdull