apache添加日期日志的方法

httpd.conf

找到这两句修改成下面语句

ErrorLog "|/httpd-xxxx/bin/rotatelogs /httpd-xxx/logs/log/error-%Y-%m-%d.log 86400 480"
CustomLog "|/httpd-xxxx/bin/rotatelogs /httpd-xxxx/logs/log/access_log-%Y-%m-%d.log 86400 480" combined

注意一定要用绝对路径,否则不会按日期生成

生成之后我想只保留7天的日志记录,所以我用linux定时器crontab

新建xxxx.sh 文件

#!/bin/sh
find /httpd-xxxx/logs/log -type f -name "access*.log" -mtime +5 | xargs rm –f;
find /httpd-xxxx/logs/log -type f -name "error*.log" -mtime +5 | xargs rm –f;

新建定时器

00 00 * * * /xxxx.sh > /dev/null 2>&1
标签:

发表评论