Logrotate can be used to ensure logs are retained based on a defined policy. This policy can be based on file age, size, and number of total similar files.
#weekly
daily
Tip
The default rotate count is 4, this should be adjusted if daily rotation is used, unless only 4 days of logs are desired.
Tip
To schedule removal of old logs add the line maxage N
to the config file, where N
is the number of days after which the log file will be deleted.
Note
Leaving the logrotate script in /etc/cron.daily is recommended, as weekly
configuration will stop logrotate from doing anything more than once a week, despite being called more often. This is especially useful when different components need to be rotated more or less often.
Portage logrotate module
To rotate log files created by portage:
FILE /etc/logrotate.d/portage
# /etc/logrotate.d/portage
/var/log/emerge-fetch.log {
createolddir 755 portage portage
olddir /var/log/portage/old
su portage portage
copytruncate
missingok
/var/log/emerge.log {
createolddir 755 portage portage
olddir /var/log/portage/old
su portage portage
copytruncate
missingok
/var/log/portage/*.log {
su portage portage
missingok
nocreate
Note
This module inherits configuration from /etc/logrotate.conf.
Note
copytruncate
will copy the file contents, then empty the file. This is useful when permissions prevent new files from being created.
Usage
Logrotate is typically called by a cron job, but can be manually used with:
root #
logrotate --verbose /etc/logrotate.conf
Tip
Rotation can be forced with --force
.
See also
- Rsyslog — open source system for high performance log processing.
- Sysklogd — utility that reads and logs messages to the system console, logs files, other machines and/or users as specified by its configuration file.
- Syslog-ng — a powerful, highly configurable monitoring and logging daemon.
© 2001–2024 Gentoo Authors
Gentoo is a trademark of the Gentoo Foundation, Inc. and of Förderverein Gentoo e.V.
The contents of this document, unless otherwise expressly stated, are licensed under the
CC-BY-SA-4.0 license.
The Gentoo Name and Logo Usage Guidelines apply.