Better (stable) names for rotated logfiles

Laurent Bercot ska-dietlibc at skarnet.org
Wed Mar 21 06:46:54 UTC 2012


>> It's mostly a straightforward change, and easy to #ifdef out--the
>> only `funny' part is that I can't just let the oldest logfile in the
>> series `get rename()'d off the end', but rather need to glob and
>> count the results.
> 
> What about a parameter that deletes log files after a specified amount
> of weeks/days/hours/minutes? That could easily be done by parsing the
> log file names during a (unsorted) directory walk. Or just delegating
> the delete of old log files into the background with a simple find
> command (fork than simply exec /bin/busybox find /var/log ... -delete)

 No, suppressing the oldest archived log file has to be part of the
rotation procedure. Separating it from the rotation (or separating
part of the rotation from the logging process) results in the race
condition that busybox's syslogd was precisely designed to avoid:
disks may fill up between rotation or suppression of archived log
files, so new logs may be lost.

 See http://www.skarnet.org/software/s6/s6-log.html#diesyslogdiedie

 The problem is that you need a straightforward way to identify managed
archived log files so you can count them, sort them and delete the oldest
one if needed at rotation time. So you have to make a compromise between
ease of identification and flexibility of your naming scheme. For the
sake of code simplicity, I went with a very rigid naming scheme in
s6-log ("timestamp.s" or "timestamp.u", timestamp being an easily
recognizable TAI64N stamp). You can be more flexible than that, but that
means that yes, you will have to glob. And make sure that your timestamp
format makes it easy to determine what the oldest log file is. (TAI64N
timestamps are naturally lexicographically ordered, which is part of the
reason I used them.)

-- 
 Laurent


More information about the busybox mailing list