summaryrefslogtreecommitdiffstats
path: root/extensions/Push/lib/Logger.pm
blob: 5d92010eea82ca5ff7672d05004f4fda51c8a1e7 (plain)
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
# 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 5.10.1;
use Moo;

use Bugzilla::Logging;
use Log::Log4perl;
use Bugzilla::Extension::Push::Constants;
use Bugzilla::Extension::Push::LogEntry;

# 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 {
    my ($this, $message) = @_;
    INFO($message);
}

sub error {
    my ($this, $message) = @_;
    ERROR($message);
}

sub debug {
    my ($this, $message) = @_;
    DEBUG($message);
}

sub result {
    my ($self, $connector, $message, $result, $data) = @_;
    $data ||= '';

    my $log_msg = sprintf
        '%s: Message #%s: %s %s',
        $connector->name,
        $message->message_id,
        push_result_to_string($result),
        $data;
    $self->info($log_msg);

    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,
    });
}

sub _build_logger { Log::Log4perl->get_logger(__PACKAGE__); }

1;