From f870849a0a422c542d6da9545e6616769a345fca Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Mon, 29 May 2023 09:05:50 +0200 Subject: [PATCH] added the new option 'log_successful_requests' #454 --- lib/HTTPServer.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/HTTPServer.pm b/lib/HTTPServer.pm index 59774cb..bec2576 100644 --- a/lib/HTTPServer.pm +++ b/lib/HTTPServer.pm @@ -35,7 +35,9 @@ sub logger { if($main::config{httpd_builtin}->{log_file}) { if(open(OUT, ">> $main::config{httpd_builtin}->{log_file}")) { if($type eq "OK") { - print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] \"$ENV{REQUEST_METHOD} $url - " . ($ENV{HTTP_USER_AGENT} || "") . "\"\n"; + if(lc($main::config{httpd_builtin}->{log_successful_requests} || "") ne "n") { + print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] \"$ENV{REQUEST_METHOD} $url - " . ($ENV{HTTP_USER_AGENT} || "") . "\"\n"; + } } elsif($type eq "NOTEXIST") { print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] File does not exist: $url\n"; } elsif($type eq "AUTHERR") { @@ -52,7 +54,9 @@ sub logger { } else { my $msg; if($type eq "OK") { - $msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] \"$ENV{REQUEST_METHOD} $url - " . ($ENV{HTTP_USER_AGENT} || "") . "\"\n"; + if(lc($main::config{httpd_builtin}->{log_successful_requests} || "") ne "n") { + $msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] \"$ENV{REQUEST_METHOD} $url - " . ($ENV{HTTP_USER_AGENT} || "") . "\"\n"; + } } elsif($type eq "NOTEXIST") { $msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] File does not exist: $url\n"; } elsif($type eq "AUTHERR") { @@ -62,7 +66,7 @@ sub logger { } else { $msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] $url\n"; } - print("$msg"); + print("$msg") if $msg; } }