From: Dave Miller Date: Sun, 28 Apr 2024 05:54:14 +0000 (-0400) Subject: Bug 1893844: configurable logging with a sensible default (#126) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=11aade46115ba45fc9f893aafdf9520cef99e106;p=thirdparty%2Fbugzilla.git Bug 1893844: configurable logging with a sensible default (#126) * Adds a localconfig var called "logging_method" which points at a config file in the conf directory (which config file to use, there are several that preconfigure log4perl to log various different ways). * Set the default to syslog. --- diff --git a/Bugzilla/Install/Localconfig.pm b/Bugzilla/Install/Localconfig.pm index 4a19b2c36..ee08842ee 100644 --- a/Bugzilla/Install/Localconfig.pm +++ b/Bugzilla/Install/Localconfig.pm @@ -102,6 +102,7 @@ use constant LOCALCONFIG_VARS => ( {name => 'memcached_namespace', default => "bugzilla:",}, {name => 'urlbase', default => '',}, {name => 'canonical_urlbase', lazy => 1}, + {name => 'logging_method', default => 'syslog'}, {name => 'nobody_user', default => 'nobody@mozilla.org'}, {name => 'attachment_base', default => '',}, {name => 'ses_username', default => '',}, diff --git a/Bugzilla/Logging.pm b/Bugzilla/Logging.pm index 870214207..9a68e51ee 100644 --- a/Bugzilla/Logging.pm +++ b/Bugzilla/Logging.pm @@ -14,6 +14,7 @@ use Log::Log4perl qw(:easy); use Log::Log4perl::MDC; use File::Spec::Functions qw(rel2abs catfile); use Bugzilla::Constants qw(bz_locations); +use Bugzilla::Install::Localconfig; use English qw(-no_match_vars $PROGRAM_NAME); sub logfile { @@ -28,7 +29,10 @@ sub fields { } BEGIN { - my $file = $ENV{LOG4PERL_CONFIG_FILE} // 'log4perl-default.conf'; + my $lc = Bugzilla::Install::Localconfig::read_localconfig(); + # Use the environment variable if it exists, otherwise use the value + # from localconfig, or if that's not set, use syslog. + my $file = $ENV{LOG4PERL_CONFIG_FILE} // ("log4perl-" . ($lc->{'logging_method'} // 'syslog') . ".conf"); Log::Log4perl::Logger::create_custom_level('NOTICE', 'WARN', 5, 2); Log::Log4perl->init(rel2abs($file, bz_locations->{confdir})); TRACE("logging enabled in $PROGRAM_NAME"); diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index 14d3311f8..2284cf8ca 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -29,7 +29,8 @@ use base qw(Exporter); get_text template_var disable_utf8 enable_utf8 detect_encoding email_filter round extract_nicks); -use Bugzilla::Logging; +# Bugzilla::Logging cannot be used it this file due to circular dependency +#use Bugzilla::Logging; use Bugzilla::Constants; use Bugzilla::RNG qw(irand); @@ -329,7 +330,6 @@ sub do_ssl_redirect_if_required { # If we're already running under SSL, never redirect. return if $ENV{HTTPS} && $ENV{HTTPS} eq 'on'; - DEBUG("Redirect to HTTPS because \$ENV{HTTPS}=$ENV{HTTPS}"); Bugzilla->cgi->redirect_to_https(); } diff --git a/RELEASE_BLOCKERS.md b/RELEASE_BLOCKERS.md index a14c3cb6a..dbd6b784e 100644 --- a/RELEASE_BLOCKERS.md +++ b/RELEASE_BLOCKERS.md @@ -58,6 +58,8 @@ app. The defaults need to be updated to log to a more generic location users are likely to have, or walk through setting it during the installation script. +**[COMPLETED]** + # Docker and Containerization I would like the Dockerfile to be rewritten such that the ENTRYPOINT is the diff --git a/conf/log4perl-default.conf b/conf/log4perl-file.conf similarity index 100% rename from conf/log4perl-default.conf rename to conf/log4perl-file.conf diff --git a/conf/log4perl-syslog.conf b/conf/log4perl-syslog.conf index 304887748..b603ef165 100644 --- a/conf/log4perl-syslog.conf +++ b/conf/log4perl-syslog.conf @@ -1,8 +1,8 @@ log4perl.rootLogger = INFO, Syslog log4perl.appender.Syslog = Log::Dispatch::Syslog log4perl.appender.Syslog.min_level = notice -log4perl.appender.Syslog.ident = apache -log4perl.appender.Syslog.facility = local4 +log4perl.appender.Syslog.ident = bugzilla +log4perl.appender.Syslog.facility = daemon log4perl.appender.Syslog.logopt = cons,pid log4perl.appender.Syslog.layout = Log::Log4perl::Layout::PatternLayout log4perl.appender.Syslog.layout.ConversionPattern = [%c] %m{chomp}%n diff --git a/template/en/default/setup/strings.txt.pl b/template/en/default/setup/strings.txt.pl index 13867aad8..449015b1e 100644 --- a/template/en/default/setup/strings.txt.pl +++ b/template/en/default/setup/strings.txt.pl @@ -222,6 +222,10 @@ END If you want to use the "Difference Between Two Patches" feature of the Patch Viewer, please specify the full path to the "interdiff" executable here. +END + localconfig_logging_method => <<'END', +This option specifies the method to use to log any errors or debug messages +create by Bugzilla. This will use the configuration found in conf/log4perl-{logging_method}.conf so anything listed there is valid. Examples are 'syslog', 'docker', 'file', and 'json'. END localconfig_memcached_servers => <<'END', If this option is set, Bugzilla will integrate with Memcached.