Reputation: 1136
I have gone through Spring Boot uses /tmp/spring.log file during testing
But that didnt help. I have a logback.xml in my spring boot application and when i start it up it creates a log in var/tmp/spring.log. Now this cant work on client site. Is there a way to configure it to not create it my log back is already logging the console in the log file i have defined in my appender. I didnt even know this was happening. and this spring.log is used with a Rolling file appender which means that it will keep on creating logs each day.
I removed:
<!--include resource="org/springframework/boot/logging/logback/base.xml"/-->
from my logback.xml but it still didnt stop it from accessing the file or creating it
any help will be appreciated
EDIT: my logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/fix.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder>
<charset>utf-8</charset>
<Pattern>%d %-5level [%thread] %logger{0}: %msg%n</Pattern>
</encoder>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>512</queueSize>
<appender-ref ref="FILE"/>
</appender>
<logger name="com.comp.myapp" level="INFO"/>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<root level="INFO">
<appender-ref ref="FILE" />
<!--<appender-ref ref="CONSOLE"/>-->
</root>
The problem that arises from this is that if i deployed the same application twice even with the same user. both applications are writing to the same file which makes no sense. If i had another spring boot application also deployed on the same machine they will write to the same spring.log in tmp folder. I dont understand whats the reason behind creating a "sneaky" log ( i would call it sneaky)
Upvotes: 6
Views: 7342
Reputation: 321
Adding
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
is indeed important, but what you ultimately want is all the features you'd get WITHOUT saving logs to tmp
. If you look at <include resource="org/springframework/boot/logging/logback/base.xml" />
you will find the following:
<included>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/spring.log}"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</included>
Therefore, you want to replace <include resource="org/springframework/boot/logging/logback/base.xml" />
with the following:
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
This way, you can still see logs in your IDE as you would if you used the base xml.
Upvotes: 8
Reputation: 366
replace
<include resource="org/springframework/boot/logging/logback/base.xml"/>
with
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
Links for details:-
https://github.com/spring-projects/spring-boot/issues/12538
Upvotes: 9