rotating log file with newsyslog on freebsd

Jump to: navigation, search


FreeBSD use /etc/newsyslog.conf to rotate log files.


/home/backup/*.log                      644  4     *    @T00  B    /var/run/  30

To end of /etc/newsyslog.conf

/home/backup/*.log		location of log files
644				chmod 644 the log file
4				Keep 4 logs
*				Don't rotate log file on size of of log
@T00				Rotate log on midnight
B				Binary, else newsyslog will add time of log generation to log files.
/var/run/		PID of Apache
30				Is signal number of gracefull restart of apache

                   $D0     rotate every night at midnight (same as @T00)
                   $D23    rotate every day at 23:00 (same as @T23)
                   $W0D23  rotate every week on Sunday at 23:00
                   $W5D16  rotate every week on Friday at 16:00
                   $M1D0   rotate at the first day of every month at midnight
                           (i.e., the start of the day; same as @01T00)
                   $M5D6   rotate on every 5th day of month at 6:00 (same as

To rotate Apache Log Add

/var/log/httpd-access_log  644  7   100   24   B   /var/run/ 30

sig_num, we use 30 to restart apache

You can find path to from httpd.conf

# grep PidFile /usr/local/etc/apache/httpd.conf
# PidFile: The file in which the server should record its process
PidFile /var/run/