Skip to content

Commit

Permalink
Bug 1893844: configurable logging with a sensible default (#126)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
justdave committed Apr 28, 2024
1 parent 1bd5d7d commit 11aade4
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions Bugzilla/Install/Localconfig.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '',},
Expand Down
6 changes: 5 additions & 1 deletion Bugzilla/Logging.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions Bugzilla/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 2 additions & 0 deletions RELEASE_BLOCKERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions conf/log4perl-syslog.conf
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions template/en/default/setup/strings.txt.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 11aade4

Please sign in to comment.