Search:  
Gentoo Wiki

Logrotate

logrotate is a tool for log maintenance. Log files tend to grow, and from time to time you have to rotate them (delete them and create new ones). Instead of deleting you may move them to some other place, compress, mail etc. logrotate can automate this process.

Contents

Installation

Just emerge it: emerge -av logrotate. A cronjob should be added automatically. Logrotate is called once per day by default but it doesn't mean your logs will be rotated daily. If you want to change the parameters logrotate is being called with, you can edit them in /etc/cron.daily/logrotate.cron.

Configuration

Main configuration file is /etc/logrotate.conf, other configuration files are included from /etc/logrotate.d/ directory.

Syntax

/var/log/wtmp {
    monthly
    create 0664 root utmp
    rotate 1
}

The basic element of the configuration file is a section. It consists of a log file to rotate (/var/log/wtmp in this example), and options in curly braces. When you specify an option outside of any section, it is interpreted as a default setting.

Examples

File: /etc/logrotate.d/apache2
/var/log/apache2/*.log {
        weekly
        missingok
        rotate 2
        compress
        delaycompress
        notifempty
        sharedscripts
        postrotate
                if [ -f /var/run/apache.pid ]; then
                        /etc/init.d/apache2 restart > /dev/null
                fi
        endscript
}
File: /etc/logrotate.d/syslog-ng
/var/log/messages {
    rotate 7
    weekly
    compress
    size 50M
    notifempty
    delaycompress
    sharedscripts
    postrotate
        /etc/init.d/syslog-ng reload > /dev/null 2>&1 || true
    endscript
}

Common options reference

for more options see man logrotate

Bugs

Do not select to rotate and compress /var/log/emerge.log files. Doing so will break Genlop trying to read emerge times. For some reason, Genlop cannot read anything else but the default "/var/log/emerge.log" named file.

Troubleshooting

If you're having problems with logrotate not rotating your logs, try running it manually with the -d option to force a debug output: /usr/sbin/logrotate -dv /etc/logrotate.conf.

Note with the -d option, logrotate will NOT actually rotate your logs, it must be run without the -d option to rotate.

See also

Retrieved from "http://www.gentoo-wiki.info/Logrotate"

Last modified: Fri, 05 Sep 2008 09:00:00 +0000 Hits: 22,748