linux中可以使用logrotate 用来进行日志的管理
logrotate的默认配置文件为 /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 9 weeks worth of backlogs
rotate 9
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
minsize 1M
rotate 9
}
/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 9
}
# system-specific logs may be also be configured here.
注意到其中有一个 include,它包含了/etc/logrotate.d/目录
所以可以将自定义配置放入到该目录下
当系统(使用crontab)或者手动调用logrotate /etc/logrotate.conf 时候,会自动调用/etc/logrotate.d/目录下的所有配置文件,同时,该目录中的配置文件会继承到/etc/logrotate.conf 中的全局参数
而手动调用 logrotate /etc/logrotate.d/XXX 的时候, XXX并不能继承到 /etc/logrotate.conf 中定义的全局变量