2015-09-08 27 views
1

我們的網絡應用程序使用CGI :: Application :: Plugin :: Session模塊存儲會話值以指示客戶端的位置。該值不是網址的一部分,我們不需要或不想爲每個位置使用虛擬主機。我想讓Apache將error_log實時分割爲單獨的「位置」日誌,而不是使用或創建後期處理解析器。我認爲要走的路要通過將日誌記錄傳輸到外部程序來處理拆分,使用下面的語法,但我不確定如何在運行時通過外部程序訪問會話位置值:

ErrorLog "|/usr/local/etc/apache24/some_program.pl" 

這甚至有可能嗎?

回答

1

是的,這是可能的。我們用下面的配置,從我們的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+at\s+\/\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 

} 
+0

你過濾上不會包含會話消息我需要的價值。它在會話本身不是標準輸入。此外,我不想添加數據到標準輸入流(如位置)。我只想知道是否有辦法訪問正在生成流的會話。 –

+0

有關如何將會話ID添加到apache日誌,請參閱http://serverfault.com/questions/418110/how-to-log-session-id-into-apache-http-server-access-log。 您可以在apache記錄器中或處理請求的代碼中處理此操作(並省略日誌記錄消息)。 – xxfelixxx

相關問題