我们的web应用程序使用CGI::Application::Plugin:: session模块存储一个会话值来指示客户端的位置。这个值不是url的一部分,我们不需要也不想为每个位置使用虚拟主机。我想让Apache实时地将error_log拆分为单独的"location"日志,而不是通过使用或创建一个后期处理解析器。我认为要走的方式是通过管道记录到一个外部程序来处理分割,使用下面的语法,但我不确定如何在运行时通过外部程序访问会话位置值:
ErrorLog "|/usr/local/etc/apache24/some_program.pl"
这可能吗?
是的,这是可能的。我们使用以下配置从apache日志中过滤掉一些噪音:
ErrorLog "|/etc/httpd/conf/apache_log_handler.pl >> /service/httpd-err/s"
我们的自定义apache_log_handler.pl
如下所示:
#!/usr/bin/perl
$|=1;
my $warning_message_to_drop_reg = qr/constant subroutine.+redefined|prototype mismatch|^s+ats+/w+/i;
while (<STDIN>) {
my $message = $_;
next if ($message =~ /$warnings_message_to_drop_reg/);
# You should add custom code here, to write to other locations, if desired
# If you log your session id, you can grab it here to decide what to do.
print $message; # Goes to normal apache error log
}