Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using logrotate with logback

When using logback in conjunction with logrotate, what is the recommended configuration? Based on a survey blogs and such, the implicit recommended configuration is to use FileAppender.append=true and then logrotate's copytruncate option.

Is this correct? Are there dragons here I need to be aware of?

like image 875
Nino Walker Avatar asked Sep 30 '13 23:09

Nino Walker


1 Answers

Having done this for multiple customers for many years, the favored approach has been to use TimeBasedRollingPolicy, rolling daily (can set to any frequency) and setting MaxHistory to desired number of days (often has been 30).

While I like and use logrotate for other log files, Logback's built in rolling means logrotate has not been necessary for my customers.

To coordinate across apps/centralize, Logback can include other Logback config files, so you can define a standard appender snippet in a file (Logback supports properties, so the including file can define the info as needed).

Even with the above, there may be desires that logrotate has that Logback does not... however I wanted to share the TimeBasedRollingPolicy in case it was overlooked.

At minimum, this approach could have logrotate work on the Logback rolled file, avoiding the potential issues with logrotate operating on the active Logback log file.

And keeping the logs isolated (don't mix the app logs into the syslog) has been very helpful with troubleshooting (apps and system) - neither has to deal with the others' noise.

like image 118
Jeff Avatar answered Sep 28 '22 02:09

Jeff