line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Logger; |
2
|
|
|
|
|
|
|
|
3
|
110
|
|
|
110
|
|
3433983
|
use strict; |
|
110
|
|
|
|
|
131
|
|
|
110
|
|
|
|
|
2469
|
|
4
|
110
|
|
|
110
|
|
340
|
use warnings; |
|
110
|
|
|
|
|
116
|
|
|
110
|
|
|
|
|
2445
|
|
5
|
110
|
|
|
110
|
|
330
|
use base qw/Exporter/; |
|
110
|
|
|
|
|
150
|
|
|
110
|
|
|
|
|
8509
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
110
|
|
|
|
|
9356
|
LOG_DEBUG2 => 5, |
9
|
|
|
|
|
|
|
LOG_DEBUG => 4, |
10
|
|
|
|
|
|
|
LOG_INFO => 3, |
11
|
|
|
|
|
|
|
LOG_WARNING => 1, |
12
|
|
|
|
|
|
|
LOG_ERROR => 1, |
13
|
|
|
|
|
|
|
LOG_NONE => 0, |
14
|
110
|
|
|
110
|
|
416
|
}; |
|
110
|
|
|
|
|
114
|
|
15
|
|
|
|
|
|
|
|
16
|
110
|
|
|
110
|
|
1209
|
use English qw(-no_match_vars); |
|
110
|
|
|
|
|
2434
|
|
|
110
|
|
|
|
|
545
|
|
17
|
110
|
|
|
110
|
|
39791
|
use UNIVERSAL::require; |
|
110
|
|
|
|
|
20338
|
|
|
110
|
|
|
|
|
641
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT = qw/LOG_DEBUG2 LOG_DEBUG LOG_INFO LOG_WARNING LOG_ERROR LOG_NONE/; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
97
|
|
|
97
|
1
|
132324
|
my ($class, %params) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $self = { |
25
|
97
|
100
|
|
|
|
463
|
verbosity => defined $params{verbosity} ? $params{verbosity} : LOG_INFO, |
26
|
|
|
|
|
|
|
}; |
27
|
97
|
|
|
|
|
194
|
bless $self, $class; |
28
|
|
|
|
|
|
|
|
29
|
97
|
|
|
|
|
136
|
my %backends; |
30
|
97
|
100
|
|
|
|
268
|
foreach ( |
31
|
86
|
|
|
|
|
299
|
$params{backends} ? @{$params{backends}} : 'Stderr' |
32
|
|
|
|
|
|
|
) { |
33
|
99
|
|
|
|
|
276
|
my $backend = ucfirst($_); |
34
|
99
|
50
|
|
|
|
356
|
next if $backends{$backend}; |
35
|
99
|
|
|
|
|
246
|
my $package = "FusionInventory::Agent::Logger::$backend"; |
36
|
99
|
|
|
|
|
605
|
$package->require(); |
37
|
99
|
50
|
|
|
|
31151
|
if ($EVAL_ERROR) { |
38
|
0
|
|
|
|
|
0
|
print STDERR |
39
|
|
|
|
|
|
|
"Failed to load Logger backend $backend: ($EVAL_ERROR)\n"; |
40
|
0
|
|
|
|
|
0
|
next; |
41
|
|
|
|
|
|
|
} |
42
|
99
|
|
|
|
|
232
|
$backends{$backend} = 1; |
43
|
|
|
|
|
|
|
|
44
|
99
|
|
|
|
|
455
|
$self->debug("Logger backend $backend initialised"); |
45
|
|
|
|
|
|
|
push |
46
|
99
|
|
|
|
|
140
|
@{$self->{backends}}, |
|
99
|
|
|
|
|
650
|
|
47
|
|
|
|
|
|
|
$package->new(%params); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
97
|
|
|
|
|
590
|
$self->debug($FusionInventory::Agent::VERSION_STRING); |
51
|
|
|
|
|
|
|
|
52
|
97
|
|
|
|
|
365
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _log { |
56
|
2244
|
|
|
2244
|
|
3405
|
my ($self, %params) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# levels: debug2, debug, info, error, fault |
59
|
2244
|
|
50
|
|
|
3359
|
my $level = $params{level} || 'info'; |
60
|
2244
|
|
|
|
|
1620
|
my $message = $params{message}; |
61
|
|
|
|
|
|
|
|
62
|
2244
|
100
|
|
|
|
2587
|
return unless $message; |
63
|
|
|
|
|
|
|
|
64
|
2189
|
|
|
|
|
1984
|
chomp($message); |
65
|
|
|
|
|
|
|
|
66
|
2189
|
|
|
|
|
1628
|
foreach my $backend (@{$self->{backends}}) { |
|
2189
|
|
|
|
|
3268
|
|
67
|
2132
|
|
|
|
|
3961
|
$backend->addMessage ( |
68
|
|
|
|
|
|
|
level => $level, |
69
|
|
|
|
|
|
|
message => $message |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub debug2 { |
75
|
63
|
|
|
63
|
1
|
351
|
my ($self, $message) = @_; |
76
|
|
|
|
|
|
|
|
77
|
63
|
100
|
|
|
|
175
|
return unless $self->{verbosity} >= LOG_DEBUG2; |
78
|
1
|
|
|
|
|
2
|
$self->_log(level => 'debug2', message => $message); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub debug { |
82
|
445
|
|
|
445
|
1
|
3067
|
my ($self, $message) = @_; |
83
|
|
|
|
|
|
|
|
84
|
445
|
100
|
|
|
|
1808
|
return unless $self->{verbosity} >= LOG_DEBUG; |
85
|
157
|
|
|
|
|
303
|
$self->_log(level => 'debug', message => $message); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub debug_result { |
89
|
0
|
|
|
0
|
1
|
0
|
my ($self, %params) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
0
|
return unless $self->{verbosity} >= LOG_DEBUG; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
0
|
|
|
0
|
my $status = $params{status} || ($params{data} ? 'success' : 'no result'); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$self->_log( |
96
|
|
|
|
|
|
|
level => 'debug', |
97
|
0
|
|
|
|
|
0
|
message => sprintf('- %s: %s', $params{action}, $status) |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub info { |
102
|
2051
|
|
|
2051
|
1
|
10148
|
my ($self, $message) = @_; |
103
|
|
|
|
|
|
|
|
104
|
2051
|
50
|
|
|
|
3409
|
return unless $self->{verbosity} >= LOG_INFO; |
105
|
2051
|
|
|
|
|
2539
|
$self->_log(level => 'info', message => $message); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub warning { |
109
|
3
|
|
|
3
|
1
|
1682
|
my ($self, $message) = @_; |
110
|
|
|
|
|
|
|
|
111
|
3
|
50
|
|
|
|
12
|
return unless $self->{verbosity} >= LOG_WARNING; |
112
|
3
|
|
|
|
|
8
|
$self->_log(level => 'warning', message => $message); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub error { |
116
|
32
|
|
|
32
|
1
|
1636
|
my ($self, $message) = @_; |
117
|
|
|
|
|
|
|
|
118
|
32
|
50
|
|
|
|
95
|
return unless $self->{verbosity} >= LOG_ERROR; |
119
|
32
|
|
|
|
|
201
|
$self->_log(level => 'error', message => $message); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
__END__ |