]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1455493 - cleanup push connector logging
authorDylan William Hardison <dylan@hardison.net>
Fri, 20 Apr 2018 20:57:10 +0000 (16:57 -0400)
committerdklawren <dklawren@users.noreply.github.com>
Fri, 20 Apr 2018 20:57:10 +0000 (16:57 -0400)
extensions/Push/lib/Backoff.pm
extensions/Push/lib/Config.pm
extensions/Push/lib/Connectors.pm
extensions/Push/lib/Push.pm

index f0116a2a7b6f536060f5a432614c65552212cc01..0436cdf145b240b428255671d44bc8a7271f7664 100644 (file)
@@ -19,6 +19,7 @@ use constant AUDIT_REMOVES => 0;
 use constant USE_MEMCACHED => 0;
 
 use Bugzilla;
+use Bugzilla::Logging;
 use Bugzilla::Util;
 
 #
@@ -67,9 +68,7 @@ sub reset {
     my ($self) = @_;
     $self->{next_attempt_ts} = Bugzilla->dbh->selectrow_array('SELECT NOW()');
     $self->{attempts} = 0;
-    Bugzilla->push_ext->logger->debug(
-        sprintf("resetting backoff for %s", $self->connector)
-    );
+    INFO( sprintf 'resetting backoff for %s', $self->connector );
 }
 
 sub inc {
@@ -82,8 +81,8 @@ sub inc {
 
     $self->{next_attempt_ts} = $date;
     $self->{attempts} = $attempts;
-    Bugzilla->push_ext->logger->debug(
-        sprintf("setting next attempt for %s to %s (attempt %s)", $self->connector, $date, $attempts)
+    INFO(
+        sprintf 'setting next attempt for %s to %s (attempt %s)', $self->connector, $date, $attempts
     );
 }
 
index 337c2696d66597180f8b49e767e688fdbdd52c6a..2db95b972d898409e6011b50c6b69d470c8f4f6d 100644 (file)
@@ -11,7 +11,7 @@ use 5.10.1;
 use strict;
 use warnings;
 
-use Bugzilla;
+use Bugzilla::Logging;
 use Bugzilla::Constants;
 use Bugzilla::Extension::Push::Option;
 use Crypt::CBC;
@@ -52,7 +52,6 @@ sub option {
 sub load {
     my ($self) = @_;
     my $config = {};
-    my $logger = Bugzilla->push_ext->logger;
 
     # prime $config with defaults
     foreach my $rh ($self->options) {
@@ -81,7 +80,7 @@ sub load {
     # done, update self
     foreach my $name (keys %$config) {
         my $value = $self->option($name)->{type} eq 'password' ? '********' : $config->{$name};
-        $logger->debug(sprintf("%s: set %s=%s\n", $self->{_name}, $name, $value || ''));
+        TRACE( sprintf "%s: set %s=%s\n", $self->{_name}, $name, $value || '' );
         $self->{$name} = $config->{$name};
     }
 }
index 75a5083ff537f9719daa45d802f915782e7202b5..d3c55d3ca685d357766b19b420313810342bc0cd 100644 (file)
@@ -11,10 +11,12 @@ use 5.10.1;
 use strict;
 use warnings;
 
+use Bugzilla::Logging;
 use Bugzilla::Extension::Push::Util;
 use Bugzilla::Constants;
 use Bugzilla::Util qw(trick_taint);
 use File::Basename;
+use Try::Tiny;
 
 sub new {
     my ($class) = @_;
@@ -25,16 +27,15 @@ sub new {
     $self->{objects} = {};
     $self->{path} = bz_locations->{'extensionsdir'} . '/Push/lib/Connector';
 
-    my $logger = Bugzilla->push_ext->logger;
     foreach my $file (glob($self->{path} . '/*.pm')) {
         my $name = basename($file);
         $name =~ s/\.pm$//;
         next if $name eq 'Base';
         if (length($name) > 32) {
-            $logger->info("Ignoring connector '$name': Name longer than 32 characters");
+            WARN("Ignoring connector '$name': Name longer than 32 characters");
         }
         push @{$self->{names}}, $name;
-        $logger->debug("Found connector '$name'");
+        TRACE("Found connector '$name'");
     }
 
     return $self;
@@ -44,7 +45,6 @@ sub _load {
     my ($self) = @_;
     return if scalar keys %{$self->{objects}};
 
-    my $logger = Bugzilla->push_ext->logger;
     foreach my $name (@{$self->{names}}) {
         next if exists $self->{objects}->{$name};
         my $file = $self->{path} . "/$name.pm";
@@ -52,34 +52,30 @@ sub _load {
         require $file;
         my $package = "Bugzilla::Extension::Push::Connector::$name";
 
-        $logger->debug("Loading connector '$name'");
+        TRACE("Loading connector '$name'");
         my $old_error_mode = Bugzilla->error_mode;
         Bugzilla->error_mode(ERROR_MODE_DIE);
-        eval {
+        try {
             my $connector = $package->new();
             $connector->load_config();
             $self->{objects}->{$name} = $connector;
+        } catch {
+            ERROR("Connector '$name' failed to load: " . clean_error($_));
         };
-        if ($@) {
-            $logger->error("Connector '$name' failed to load: " . clean_error($@));
-        }
         Bugzilla->error_mode($old_error_mode);
     }
 }
 
 sub stop {
     my ($self) = @_;
-    my $logger = Bugzilla->push_ext->logger;
     foreach my $connector ($self->list) {
         next unless $connector->enabled;
-        $logger->debug("Stopping '" . $connector->name . "'");
-        eval {
+        TRACE("Stopping '" . $connector->name . "'");
+        try {
             $connector->stop();
+        } catch {
+            ERROR("Connector '" . $connector->name . "' failed to stop: " . clean_error($_));
         };
-        if ($@) {
-            $logger->error("Connector '" . $connector->name . "' failed to stop: " . clean_error($@));
-            $logger->debug("Connector '" . $connector->name . "' failed to stop: $@");
-        }
     }
 }
 
index 45b9b05dd581f8b91a4e5cbdd7e39ebd9159a0a5..670b2aa56d4c57b21debdb36418fdd744dd4b331 100644 (file)
@@ -11,6 +11,7 @@ use 5.10.1;
 use strict;
 use warnings;
 
+use Bugzilla::Logging;
 use Bugzilla::Extension::Push::BacklogMessage;
 use Bugzilla::Extension::Push::Config;
 use Bugzilla::Extension::Push::Connectors;
@@ -107,7 +108,7 @@ sub push {
 
             # if the connector is backlogged, push to the backlog queue
             if ($is_backlogged) {
-                $logger->debug("backlogged");
+                INFO('connector is backlogged');
                 my $backlog = Bugzilla::Extension::Push::BacklogMessage->create_from_message($message, $connector);
             }
         }