我试图让 apache 根据当前日期每天创建一个新的错误日志文件。默认的错误日志文件名是这样的:ErrorLog "/logs/error.log"
我希望它是这样的: ErrorLog "/logs/error_$year$month$day.log"
有任何想法吗?
我试图让 apache 根据当前日期每天创建一个新的错误日志文件。默认的错误日志文件名是这样的:ErrorLog "/logs/error.log"
我希望它是这样的: ErrorLog "/logs/error_$year$month$day.log"
有任何想法吗?
看看Cronolog
cronolog 是一个简单的过滤程序,它从标准输入读取日志文件条目,并将每个条目写入由文件名模板和当前日期和时间指定的输出文件。当扩展文件名改变时,当前文件被关闭并打开一个新文件。cronolog 旨在与 Web 服务器(如 Apache)结合使用,以将访问日志拆分为每日或每月日志。
我的方法是为 apache 配置logrotate以每天轮换一次 apache 的日志然后..
对于在每个日志行上都有日期信息的自定义日志:
%...{format}t: The time, in the form given by format, which should
be in strftime(3) format. (potentially localized)
您必须使用 strftime (man 3 strftime) 格式化规则:
%F or its equivalent without dashes %Y%m%d
所以:
# CustomLog with explicit format string
CustomLog my_log "%{%Y%m%d}t %h %l %u %t \"%r\" %>s %b"
%{%Y%m%d}t在哪里完成这项工作
在您的 httpd.conf 中更改为这个
ErrorLog "|bin/rotatelogs /var/logs/errorlog.%Y-%m-%d-%H_%M_%S 5M"
此配置将在错误日志文件大小达到 5 兆字节时对其进行轮换,并且日志文件名称的后缀将以 errorlog.YYYY-mm-dd-HH_MM_SS 形式创建。