3

According to spring boot 1.4 docs spring boot automatically rotates log file as file size reaches 10MB. I have spring boot v1.4.2 service deployed on a linux machine, but the file doesn't rotate. The file has reached 118 MB and still doesn't automatically rotate.

Am I missing something in the docs, or a bug?

Juzer Ali
  • 4,109
  • 3
  • 35
  • 62
  • do you just have the default log configuration or do you use any extra file? And service deployed on a linux machine means you created a symlink and starts the service with `service .. start`? – Patrick Feb 02 '17 at 07:53
  • @Patrick its exactly how you said it. There is a symlink in `/etc/init.d/` and we start the service with `service appname start`. There is no logging configuration except log levels, everything is default. – Juzer Ali Feb 02 '17 at 10:01
  • Did you have any luck with this? I am facing the same issue. – szmeti Dec 19 '17 at 13:47
  • @szmeti Yes, I will answer – Juzer Ali Dec 20 '17 at 08:36
  • @JuzerAli please always mark answers as accepted if they help to solve your problems. You can [accept your own answer](https://stackoverflow.blog/2009/01/06/accept-your-own-answers/). Having an accepted answer prevents the related post from appearing in [Unanswered Questions](https://stackoverflow.com/unanswered) tab on the main page. Follow recommendations from [Help Center](https://stackoverflow.com/help/someone-answers). – naXa stands with Ukraine Feb 21 '18 at 13:54
  • I'd like to link a similar question (not duplicate): [Log rotation in Spring Boot service](https://stackoverflow.com/q/48681916/1429387) – naXa stands with Ukraine Feb 21 '18 at 14:05

2 Answers2

2

Another option for log rotation on Linux machines is to use logrotate with copytruncate parameter.

logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.

logrotate reads everything about the log files it should be handling from the series of configuration files specified on the command line. Each configuration file can set global options (local definitions override global ones, and later definitions override earlier ones) and specify logfiles to rotate. A simple configuration file looks like this:

copytruncate

Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one. It can be used when some program cannot be told to close its logfile and thus might continue writing (appending) to the previous log file forever. Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place.

Add this entry to logrotate configuration file

/var/log/spring.log {
    daily
    copytruncate
    rotate 3
    dateext
    notifempty
}

What's next? See How to make log-rotate change take effect?

logrotate uses crontab to work. It's scheduled work, not a daemon, so no need to reload its configuration.

Community
  • 1
  • 1
naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
1

Spring rotates logs only for file appender. For logging in /var/log/spring.log spring uses a console appender, which cannot be configured to rotate. Only file appenders can be configured to rotate. I ended up configuring logback-spring.xml to append logs in a file in addition to the console. Thus whenever my /var/log/<> grows too large, I simply delete it.

Juzer Ali
  • 4,109
  • 3
  • 35
  • 62