line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Armadito::Agent::Logger; |
2
|
|
|
|
|
|
|
|
3
|
29
|
|
|
29
|
|
1274635
|
use strict; |
|
29
|
|
|
|
|
52
|
|
|
29
|
|
|
|
|
743
|
|
4
|
29
|
|
|
29
|
|
95
|
use warnings; |
|
29
|
|
|
|
|
40
|
|
|
29
|
|
|
|
|
792
|
|
5
|
29
|
|
|
29
|
|
95
|
use base qw/Exporter/; |
|
29
|
|
|
|
|
66
|
|
|
29
|
|
|
|
|
2467
|
|
6
|
|
|
|
|
|
|
|
7
|
29
|
|
|
29
|
|
14269
|
use Readonly; |
|
29
|
|
|
|
|
85440
|
|
|
29
|
|
|
|
|
2672
|
|
8
|
|
|
|
|
|
|
Readonly my $LOG_DEBUG2 => 5; |
9
|
|
|
|
|
|
|
Readonly my $LOG_DEBUG => 4; |
10
|
|
|
|
|
|
|
Readonly my $LOG_INFO => 3; |
11
|
|
|
|
|
|
|
Readonly my $LOG_WARNING => 2; |
12
|
|
|
|
|
|
|
Readonly my $LOG_ERROR => 1; |
13
|
|
|
|
|
|
|
Readonly my $LOG_NONE => 0; |
14
|
|
|
|
|
|
|
|
15
|
29
|
|
|
29
|
|
151
|
use English qw(-no_match_vars); |
|
29
|
|
|
|
|
39
|
|
|
29
|
|
|
|
|
201
|
|
16
|
29
|
|
|
29
|
|
9968
|
use UNIVERSAL::require; |
|
29
|
|
|
|
|
55
|
|
|
29
|
|
|
|
|
224
|
|
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
0
|
|
sub LOG_DEBUG2 { return $LOG_DEBUG2 } |
19
|
0
|
|
|
0
|
0
|
|
sub LOG_DEBUG { return $LOG_DEBUG } |
20
|
0
|
|
|
0
|
0
|
|
sub LOG_INFO { return $LOG_INFO } |
21
|
0
|
|
|
0
|
0
|
|
sub LOG_WARNING { return $LOG_WARNING } |
22
|
0
|
|
|
0
|
0
|
|
sub LOG_ERROR { return $LOG_ERROR } |
23
|
0
|
|
|
0
|
0
|
|
sub LOG_NONE { return $LOG_NONE } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our @EXPORT_OK = qw/LOG_DEBUG2 LOG_DEBUG LOG_INFO LOG_WARNING LOG_ERROR LOG_NONE/; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
0
|
|
|
0
|
1
|
|
my ( $class, %params ) = @_; |
29
|
0
|
0
|
|
|
|
|
my $self = { verbosity => defined $params{verbosity} ? $params{verbosity} : $LOG_INFO }; |
30
|
0
|
|
|
|
|
|
bless $self, $class; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my %backends; |
33
|
0
|
0
|
|
|
|
|
foreach ( $params{backends} ? @{ $params{backends} } : 'Stderr' ) { |
|
0
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $backend = ucfirst($_); |
35
|
0
|
0
|
|
|
|
|
next if $backends{$backend}; |
36
|
0
|
|
|
|
|
|
my $package = "Armadito::Agent::Logger::$backend"; |
37
|
0
|
|
|
|
|
|
$package->require(); |
38
|
0
|
0
|
|
|
|
|
if ($EVAL_ERROR) { |
39
|
0
|
|
|
|
|
|
print "Failed to load Logger backend $backend: ($EVAL_ERROR)\n"; |
40
|
0
|
|
|
|
|
|
next; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$backends{$backend} = 1; |
44
|
0
|
|
|
|
|
|
push( @{ $self->{backends} }, $package->new(%params) ); |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->debug("Logger backend $backend initialised"); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$self->debug($Armadito::Agent::VERSION_STRING); |
50
|
0
|
|
|
|
|
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _log { |
54
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# levels: debug2, debug, info, error, fault |
57
|
0
|
|
0
|
|
|
|
my $level = $params{level} || 'info'; |
58
|
0
|
|
|
|
|
|
my $message = $params{message}; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
return unless $message; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
chomp($message); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
foreach my $backend ( @{ $self->{backends} } ) { |
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$backend->addMessage( |
66
|
|
|
|
|
|
|
level => $level, |
67
|
|
|
|
|
|
|
message => $message |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub debug2 { |
73
|
0
|
|
|
0
|
1
|
|
my ( $self, $message ) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
return unless $self->{verbosity} >= $LOG_DEBUG2; |
76
|
0
|
|
|
|
|
|
$self->_log( level => 'debug2', message => $message ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub debug { |
80
|
0
|
|
|
0
|
1
|
|
my ( $self, $message ) = @_; |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
return unless $self->{verbosity} >= $LOG_DEBUG; |
83
|
0
|
|
|
|
|
|
$self->_log( level => 'debug', message => $message ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub debug_result { |
87
|
0
|
|
|
0
|
1
|
|
my ( $self, %params ) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
return unless $self->{verbosity} >= $LOG_DEBUG; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
0
|
|
|
|
my $status = $params{status} || ( $params{data} ? 'success' : 'no result' ); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$self->_log( |
94
|
|
|
|
|
|
|
level => 'debug', |
95
|
0
|
|
|
|
|
|
message => sprintf( '- %s: %s', $params{action}, $status ) |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub info { |
100
|
0
|
|
|
0
|
1
|
|
my ( $self, $message ) = @_; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
return unless $self->{verbosity} >= $LOG_INFO; |
103
|
0
|
|
|
|
|
|
$self->_log( level => 'info', message => $message ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub warning { |
107
|
0
|
|
|
0
|
1
|
|
my ( $self, $message ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
return unless $self->{verbosity} >= $LOG_WARNING; |
110
|
0
|
|
|
|
|
|
$self->_log( level => 'warning', message => $message ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub error { |
114
|
0
|
|
|
0
|
1
|
|
my ( $self, $message ) = @_; |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
return unless $self->{verbosity} >= $LOG_ERROR; |
117
|
0
|
|
|
|
|
|
$self->_log( level => 'error', message => $message ); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
__END__ |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 NAME |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Armadito::Agent::Logger - Armadito Agent logger |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 DESCRIPTION |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This is the logger object. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 METHODS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 new(%params) |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
The constructor. The following parameters are allowed, as keys of the %params |
136
|
|
|
|
|
|
|
hash: |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=over |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item I<config> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
the agent configuration object, to be passed to backends |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item I<backends> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
a list of backends to use (default: Stderr) |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item I<verbosity> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
the verbosity level (default: LOG_INFO) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 debug2($message) |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Add a log message with debug2 level. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 debug($message) |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Add a log message with debug level. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 info($message) |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Add a log message with info level. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 warning($message) |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Add a log message with warning level. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 error($message) |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Add a log message with error level. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 debug_result(%params) |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Add a log message with debug level related to an action result. |