1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
package Bugzilla::Extension::Push::Logger;
use strict;
use warnings;
use Apache2::Log;
use Bugzilla::Extension::Push::Constants;
use Bugzilla::Extension::Push::LogEntry;
sub new {
my ($class) = @_;
my $self = {};
bless($self, $class);
return $self;
}
sub info { shift->_log_it('INFO', @_) }
sub error { shift->_log_it('ERROR', @_) }
sub debug { shift->_log_it('DEBUG', @_) }
sub debugging {
my ($self) = @_;
return $self->{debug};
}
sub _log_it {
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 result {
my ($self, $connector, $message, $result, $data) = @_;
$data ||= '';
$self->info(sprintf(
"%s: Message #%s: %s %s",
$connector->name,
$message->message_id,
push_result_to_string($result),
$data
));
Bugzilla::Extension::Push::LogEntry->create({
message_id => $message->message_id,
change_set => $message->change_set,
routing_key => $message->routing_key,
connector => $connector->name,
push_ts => $message->push_ts,
processed_ts => Bugzilla->dbh->selectrow_array('SELECT NOW()'),
result => $result,
data => $data,
});
}
1;
|