How To Manage Log Files With logadm

logadm is a handy Solaris utility that can be used to rotate log files. It is invoked from cron and runs off the configuration file, /etc/logadm.conf. /etc/logadm.conf contains a list of log files managed by logadm and the corresponding criteria – size, age, count – and action – copy, truncate, compress – by which the logs are managed. With logadm used to rotate log files, system admins are not required to write complicated scripts to restart applications when there is a need to rotate their log files. This can be especially helpful with “chatty” applications like Apache and Tomcat whose logs tend to blow out very quickly.

The example below creates an entry in /etc/logadm.conf to manage the log /opt/bb/bbc/BBOUT. It tells logadm to keep four copies (-C 4) of the log file, BBOUT, naming them BBOUT.0, BBOUT.1, etc. as they are rotated. It also tells logadm to rotate the log file when it reaches 5 MB (-s 5m), to rotate the log file by copying it and truncating the original log file to zero length (-c), to compress old log files as they are created keeping none of the most recent log uncompressed (-z 0), and to write an entry in /etc/logadm.conf that corresponds to the current command line arguments (-w /opt/bb/bbc/BBOUT).

# logadm -C 4 -s 5m -c -z 0 -w /opt/bb/bbc/BBOUT
# tail -1 /etc/logadm.conf
/opt/bb/bbc/BBOUT -C 4 -c -s 5m -z 0