10.8. Log files
Log files should usually be named /var/log/package.log
. If you have many log files, or need a separate directory for permission reasons (/var/log
is writable only by root
), you should usually create a directory named /var/log/package
and place your log files there.
Log files must be rotated occasionally so that they don’t grow indefinitely. The best way to do this is to install a log rotation configuration file in the directory /etc/logrotate.d
, normally named /etc/logrotate.d/package
, and use the facilities provided by logrotate
. 13 Here is a good example for a logrotate config file (for more information see logrotate(8)):
/var/log/foo/*.log {
rotate 12
weekly
compress
missingok
postrotate
start-stop-daemon -K -p /var/run/foo.pid -s HUP -x /usr/sbin/foo -q
endscript
}
This rotates all files under /var/log/foo
, saves 12 compressed generations, and tells the daemon to reopen its log files after the log rotation. It skips this log rotation (via missingok
) if no such log file is present, which avoids errors if the package is removed but not purged.
Log files should be removed when the package is purged (but not when it is only removed). This should be done by the postrm
script when it is called with the argument purge
(see Details of removal and/or configuration purging).