I have a Linux program which can write information to stdout and stderr.
I have a shell script which redirects that output to a file in /var/log
. (Via >>
and 2>&1
.)
Is there a way to make that log file rotate? (max size, then switch to a different file, keep only a limited number of files)
I've seen a few answers which talk about the logrotate
program, which sounds good, but they also seem to be focused on programs which are generating log files internally and handle HUP signals. Is there a way to make this work with a basic output redirection script?
Best Answer
As an alternative, you could pipe the output through tools designed with the primary purpose of maintaining size-capped, automatically rotated, log file sets, such as:
multilog
from daemontoolsmultilog
from daemontools-encores6-log
from s6svlogd
from runittinylog
from perpcyclog
from noshTools to then process
multilog
-format log file sets include, amongst others:multilog-watch
logrange
multilog-stamptail
follow-log-directories
from noshexport-to-rsyslog
from noshFurther reading
logrotate
ornewsyslog
in this century.. Frequently Given Answers.