local log files

i’m sure the ops / sysadmins can tell you more about this than i can but here’s what i’ve found out through trial and error.

i recently noticed my local logfiles growing out of control, if you have been here for a while on the same box like me you might see something similar.

here’s what i’ve noticed.

$ ls -hl /var/log/httpd/
-rw-r--r-- 1 root wheel 23M Feb 1 00:42 local-access_log
-rw-r--r-- 1 root wheel 8M Feb 1 00:42 local-error_log

pretty big log huh?

default log files are rotated and compressed. our custom logs aren’t.

what to do?

1. reset your log file frequently or as needed.

here’s one method.

$ sudo su -
Password: ******
# cat /dev/null > /var/log/httpd/local-access_log
# cat /dev/null > /var/log/httpd/local-error_log
# exit
$ ls -hl /var/log/httpd/
-rw-r--r-- 1 root wheel 0B Feb 1 00:45 local-access_log
-rw-r--r-- 1 root wheel 0B Feb 1 00:45 local-error_log

you could also save last few lines similar like this …

# tail -n $lines messages > mesg.temp # Saves last section of message log file.
# mv mesg.temp messages # Becomes new log directory.

2. even better, set up logrotate which will rotate and compress the logs

use macports to install logrotate

$ sudo port install logrotate

then copy the config and tweak as neccassry.

$ sudo cp /opt/local/etc/logrotate-default /opt/local/etc/logrotate.conf

i added a section for local like this

/var/log/httpd/local*log {
/bin/kill -HUP `cat /opt/local/apache2/logs/httpd.pid 2>/dev/null` 2> /dev/null || true

then run logrotate manually

$ sudo logrotate /opt/local/etc/logrotate.conf -f

or even better set up a crontab

$ crontab -e

then add something like the following

0 0 * * * /opt/local/bin/logrotate -s /opt/local/var/logrotate.status /opt/local/etc/logrotate.conf > /dev/null 2>&1

windows is another story since commands and paths won’t be the same … only thing that comes to mind is
1.) stop apache, 2.) delete/rename log files, 3.) restart apache.

Post a Comment

Your email is never published nor shared. Required fields are marked *