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
請關注我們微信公眾號:mw748219