Skip to content

LogRotate

0. IntroductionLogRotate is a log management tool, which enables log files' cutting, deleting and creating, and triggered by crontab.

1. Configuration Files and PathThe default config file located/etc/logrotate.conf

In default config file, the config folder/etc/logrotate.dis included by default. Which means, config files added in this folder will be executed by logrotate process.

2. Config demo```

/var/log/***.log { # The target log file LOG_CONFIG_PARAMETERS # The parameters for logrotate } ```

3.Supported Parameters### (1). Cutting cycle- daily: The cutting cycle is daily- weekly: The cutting cycle is weekly- monthly: The cutting cycle is monthly- yearly: The cutting cycle is every year

(2). Dump size- size 50M

(3). Number of copies of log saved- rotate 1

(4). Number of days to retain logs- maxage 1

(5). Do not dump files with specified extensions- tabooext [+] list

(6). Ignore errors- missingok

(7). Backup/truncation- copytruncate/nocopytruncate

(8). Create permissions- create mode owner group- nocreate

(9). Compression- nocompress- compress

(10). Delay compression- delaycompress- nodelaycompress

(11). Execute before all other instructions are completed- prerotate- endscript

(12). Execute after all other instructions are completed- postrotate- endscript

(13). Shared scripts- sharedscripts

(14). The error message is sent to the specified email address- errors address

(15). Send the dumped log file to the specified E-mail address- mail address- nomail

(16). Empty files are also dumped- ifempty- notifempty

(17). Specify the dump directory- olddir directory- noolddir### (18). Log date suffix- dateext

(19). Log format- dateformat

(20). Date one day in advance- dateyesterday

(21). Specify the suffix of the file- extension

REF[1]. https://blog.csdn.net/xiaojin21cen/article/details/122309230

[2]. https://linux.die.net/man/8/logrotate