From fb85881651195cd97ef1499136e947dd56c3b4f3 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Wed, 28 Feb 2018 21:55:10 -0500 Subject: Bug 1437646 - add support for Log::Log4perl --- Bugzilla.pm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Bugzilla.pm') diff --git a/Bugzilla.pm b/Bugzilla.pm index c21b1ad98..a154b174b 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -11,6 +11,8 @@ use 5.10.1; use strict; use warnings; +use Bugzilla::Logging; + # We want any compile errors to get to the browser, if possible. BEGIN { # This makes sure we're in a CGI. @@ -97,6 +99,10 @@ sub init_page { binmode STDOUT, ':utf8'; } + if (i_am_cgi()) { + Log::Log4perl::MDC->put(remote_ip => remote_ip()); + } + if (${^TAINT}) { # Some environment variables are not taint safe delete @::ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; @@ -380,6 +386,10 @@ sub login { my $authenticated_user = $authorizer->login($type); + if (i_am_cgi()) { + Log::Log4perl::MDC->put(user_id => $authenticated_user->id); + } + # At this point, we now know if a real person is logged in. # Check if a password reset is required @@ -770,9 +780,8 @@ sub local_timezone { # Send messages to syslog for the auditing systems (eg. mozdef) to pick up. sub audit { my ($class, $message) = @_; - openlog('apache', 'cons,pid', 'local4'); - syslog('notice', '[audit] ' . encode_utf8($message)); - closelog(); + state $logger = Log::Log4perl->get_logger("audit"); + $logger->notice(encode_utf8($message)); } # This creates the request cache for non-mod_perl installations. @@ -887,6 +896,8 @@ sub _cleanup { foreach my $signal (qw(TERM PIPE)) { $SIG{$signal} = 'DEFAULT' if $SIG{$signal} && $SIG{$signal} eq 'IGNORE'; } + + Log::Log4perl::MDC->remove(); } sub END { -- cgit v1.2.3-24-g4f1b