Hi Community!
I'm a novice when it comes to Spring Boot, currently trying out some Spring Cloud Data Flow workflows and i noticed that there doesn't seem to be an option to turn off log rotation for logs that the application produces. I'm mainly using Docker images and after a few days i always have unnecessarily lots of log files, instead of just one that i can look into. Having an option like logging.logback.rollingpolicy.disable would be so useful for me. Do you think you can implement this feature? Thank you!
Comment From: philwebb
Writing a log file that never gets rotated could lead to disk space issues if the application runs for a long time. Have you seen the logback file rotation properties that we already support? I wonder if tuning logging.logback.rollingpolicy.max-file-size would allow you to have longer files without needing to completely disable log rotation?
Comment From: Risae
Writing a log file that never gets rotated could lead to disk space issues if the application runs for a long time. Have you seen the logback file rotation properties that we already support? I wonder if tuning
logging.logback.rollingpolicy.max-file-sizewould allow you to have longer files without needing to completely disable log rotation?
Hi and thank you for your reply! I am aware that the logfile might increase to a dangerous size, but this is not an issue here since i'm running the application inside a Docker Container. Since i have to deal with log rotation, i have to also deal with making sure that all of the logfiles get "moved" out of the Container before it restarts, instead of just declaring one file. This increases the amount of work that i have to do on my side because i cannot disable log rotation. Having a simple "switch" to turn off log rotation allows me to focus my work on improving my Spring Cloud Data Flow application and not having to worry about changing all kinds of things just to get various logs. Log rotation can be good in some situation, but sometimes having option for the program you want to create is even better! Thank you and i hope you could implement this feature!
Here is another example of someone trying the same thing but wasn't able to do this with "Application properties":
https://stackoverflow.com/questions/57964371/spring-boot-slf4j-log4j-disable-daily-rollingfilepolicy
Comment From: Hanmac
i had the same problem and i solved it in writing my own logback-spring.xml without rotation:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_PATH}${LOG_FILE}"/>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
<charset>${FILE_LOG_CHARSET}</charset>
</encoder>
<file>${LOG_FILE}</file>
</appender>
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
it isn't a size problem because the logs are getting rotated by an external service
Comment From: Risae
Hi Hanmac,
that is a solution, but this would result in another file and another place that needs to be maintained. A simple "switch" to turn off log rotation, using the Spring Boot "Application Properties" would be so much easier. Ich hoffe du verstehst was ich meine :-)
Comment From: mhalbritter
As a workaround, you can also set the value to some arbitrary high number:
logging.logback.rollingpolicy.max-file-size=10TB
Comment From: Risae
As a workaround, you can also set the value to some arbitrary high number:
logging.logback.rollingpolicy.max-file-size=10TB
Will this also disable the daily log rotation?
Comment From: mhalbritter
Ah, no, it will not. The daily log rotation is inferred from the pattern in logging.logback.rollingpolicy.file-name-pattern, which defaults to ${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz. If you change it to ${LOG_FILE}.%d{yyyy}.%i.gz it should roll over once per year. Not sure if there's a workaround which disables time based rolling completely.
Comment From: mhalbritter
Hey, we talked today about that in our meeting today. We think this is quite an exotic use case and you provided a workaround which isn't that bad, so we don't see the necessity to add a dedicated option in Spring Boot.
Comment From: Hanmac
@mhalbritter some solution that shouldn't break other code: make both this classes there changeable by variables
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
and
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
in https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/file-appender.xml
if no one is changing the variables, it should still work for them. and others can use the properties to change the Appender or the Policy without the need to overwrite the xml files.