apache添加日期日志的方法

apache by 黃業(yè)興 at 2019-10-11

找到httpd.conf

找到這兩句修改成下面語(yǔ)句

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

注意一定要用絕對(duì)路徑,否則不會(huì)按日期生成

生成之后我想只保留7天的日志記錄,所以我用linux定時(shí)器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;

新建定時(shí)器

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

請(qǐng)關(guān)注我們微信公眾號(hào):mw748219