diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-06-21 23:17:21 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-06-28 22:42:01 +0200 |
commit | 4a29d896ea90e8174ca10a8fd696e4c0767d3350 (patch) | |
tree | 1a8676fc913dd09d93f21f89d5cee5e9d5519946 | |
parent | d56c99a3286afb63266d5019069d15ab4b647106 (diff) | |
download | bugzilla-4a29d896ea90e8174ca10a8fd696e4c0767d3350.tar.gz bugzilla-4a29d896ea90e8174ca10a8fd696e4c0767d3350.tar.xz |
add request id to logs
-rw-r--r-- | Bugzilla/Quantum/Plugin/Glue.pm | 11 | ||||
-rw-r--r-- | Log/Log4perl/Layout/Mozilla.pm | 3 | ||||
-rw-r--r-- | conf/log4perl-test.conf | 4 |
3 files changed, 11 insertions, 7 deletions
diff --git a/Bugzilla/Quantum/Plugin/Glue.pm b/Bugzilla/Quantum/Plugin/Glue.pm index 112514b63..301003740 100644 --- a/Bugzilla/Quantum/Plugin/Glue.pm +++ b/Bugzilla/Quantum/Plugin/Glue.pm @@ -53,16 +53,17 @@ sub register { } ); - if ($D{HTTPD_IN_SUBDIR}) { - $app->hook( - before_dispatch => sub { + $app->hook( + before_dispatch => sub { + if ($D{HTTPD_IN_SUBDIR}) { my ($c) = @_; my $path = $c->req->url->path; $path =~ s{^/bmo}{}s; $c->req->url->path($path); } - ); - } + Log::Log4perl::MDC->put(request_id => $c->req->request_id); + } + ); Bugzilla::Extension->load_all(); if ($app->mode ne 'development') { diff --git a/Log/Log4perl/Layout/Mozilla.pm b/Log/Log4perl/Layout/Mozilla.pm index b625c54f4..4aedd9843 100644 --- a/Log/Log4perl/Layout/Mozilla.pm +++ b/Log/Log4perl/Layout/Mozilla.pm @@ -53,6 +53,9 @@ sub render { my $mdc = Log::Log4perl::MDC->get_context; my $fields = $mdc->{fields} // {}; + if ($mdc->{request_id}) { + $fields->{request_id} = $mdc->{request_id} + } my %out = ( EnvVersion => LOGGING_FORMAT_VERSION, Hostname => $HOSTNAME, diff --git a/conf/log4perl-test.conf b/conf/log4perl-test.conf index 77fc00af8..e8acd58cf 100644 --- a/conf/log4perl-test.conf +++ b/conf/log4perl-test.conf @@ -4,14 +4,14 @@ log4perl.appender.Cereal.PeerAddr=127.0.0.1 log4perl.appender.Cereal.PeerPort=5880 log4perl.appender.Cereal.defer_connection=1 log4perl.appender.Cereal.layout = Log::Log4perl::Layout::PatternLayout -log4perl.appender.Cereal.layout.ConversionPattern = %d %6p | %c | %m{chomp}%n +log4perl.appender.Cereal.layout.ConversionPattern = [%X{request_id}] %d %6p | %c | %m{chomp}%n log4perl.filter.LOG_TO_STDERR = sub { not $ENV{LOG4PERL_STDERR_DISABLE} } log4perl.appender.Screen = Log::Log4perl::Appender::Screen log4perl.appender.Screen.Filter = LOG_TO_STDERR log4perl.appender.Screen.stderr = 1 log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout -log4perl.appender.Screen.layout.ConversionPattern = %d %6p | %c | %m{chomp}%n +log4perl.appender.Screen.layout.ConversionPattern = [%X{request_id}] %d %6p | %c | %m{chomp}%n log4perl.appender.File = Log::Log4perl::Appender::File log4perl.appender.File.layout = Log::Log4perl::Layout::Mozilla |