diff options
Diffstat (limited to 'extensions/Push')
-rw-r--r-- | extensions/Push/lib/Logger.pm | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/extensions/Push/lib/Logger.pm b/extensions/Push/lib/Logger.pm index 833cb3b19..5d92010ee 100644 --- a/extensions/Push/lib/Logger.pm +++ b/extensions/Push/lib/Logger.pm @@ -8,53 +8,43 @@ package Bugzilla::Extension::Push::Logger; use 5.10.1; -use strict; -use warnings; +use Moo; +use Bugzilla::Logging; +use Log::Log4perl; use Bugzilla::Extension::Push::Constants; use Bugzilla::Extension::Push::LogEntry; -sub new { - my ($class) = @_; - my $self = {}; - bless($self, $class); - return $self; -} +# If Log4perl then finds that it's being called from a registered wrapper, it +# will automatically step up to the next call frame. +Log::Log4perl->wrapper_register(__PACKAGE__); -sub info { shift->_log_it('INFO', @_) } -sub error { shift->_log_it('ERROR', @_) } -sub debug { shift->_log_it('DEBUG', @_) } +sub info { + my ($this, $message) = @_; + INFO($message); +} -sub debugging { - my ($self) = @_; - return $self->{debug}; +sub error { + my ($this, $message) = @_; + ERROR($message); } -sub _log_it { - require Apache2::Log; - my ($self, $method, $message) = @_; - return if $method eq 'DEBUG' && !$self->debugging; - chomp $message; - if ($ENV{MOD_PERL}) { - Apache2::ServerRec::warn("Push $method: $message"); - } elsif ($ENV{SCRIPT_FILENAME}) { - print STDERR "Push $method: $message\n"; - } else { - print STDERR '[' . localtime(time) ."] $method: $message\n"; - } +sub debug { + my ($this, $message) = @_; + DEBUG($message); } sub result { my ($self, $connector, $message, $result, $data) = @_; $data ||= ''; - $self->info(sprintf( - "%s: Message #%s: %s %s", + my $log_msg = sprintf + '%s: Message #%s: %s %s', $connector->name, $message->message_id, push_result_to_string($result), - $data - )); + $data; + $self->info($log_msg); Bugzilla::Extension::Push::LogEntry->create({ message_id => $message->message_id, @@ -68,4 +58,6 @@ sub result { }); } +sub _build_logger { Log::Log4perl->get_logger(__PACKAGE__); } + 1; |