在 Apache2.4 中,我需要尽可能多地记录导致 400 错误的请求。
是否可以在不将日志记录级别设置为
debug
的情况下实现此目的?是否也可以只记录 400 个错误而不记录任何其他 4XX?
谢谢!
将日志记录级别设置为
debug
可能会起作用,但它会记录太多错误(404、403 ...),而我不需要它
将
/tmp/400errors.log
更改为您想要记录输出的位置
在apache中使用
SetEnvIf
将此添加到
httpd.conf
# Set an environment variable for 400 series errors
SetEnvIfNoCase Response_Status "^400" LOG_400_ERRORS
# Define a custom log format that includes the error status
LogFormat "%h %l %u %t \"%r\" %>s \"%{Referer}i\" \"%{User-Agent}i\"" combined_with_status
# Use conditional logging based on the environment variable
CustomLog /tmp/400errors.log combined_with_status env=LOG_400_ERRORS
在 apache 中使用
mod_rewrite
,无论是在站点配置中,还是在 htaccess 文件中
RewriteEngine On
# Redirect 400 series errors to a custom error log
RewriteCond %{REQUEST_STATUS} ^400
RewriteRule ^ - [E=LOG_400_ERRORS]
# Define a custom log format that includes the error status
LogFormat "%h %l %u %t \"%r\" %>s \"%{Referer}i\" \"%{User-Agent}i\"" combined_with_status
# Use conditional logging based on the environment variable
CustomLog /tmp/400errors.log combined_with_status env=LOG_400_ERRORS