line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Logger; |
2
|
|
|
|
|
|
|
|
3
|
99
|
|
|
99
|
|
4364691
|
use strict; |
|
99
|
|
|
|
|
204
|
|
|
99
|
|
|
|
|
2713
|
|
4
|
99
|
|
|
99
|
|
517
|
use warnings; |
|
99
|
|
|
|
|
188
|
|
|
99
|
|
|
|
|
3109
|
|
5
|
99
|
|
|
99
|
|
499
|
use base qw/Exporter/; |
|
99
|
|
|
|
|
253
|
|
|
99
|
|
|
|
|
9885
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
99
|
|
|
|
|
12685
|
LOG_DEBUG2 => 5, |
9
|
|
|
|
|
|
|
LOG_DEBUG => 4, |
10
|
|
|
|
|
|
|
LOG_INFO => 3, |
11
|
|
|
|
|
|
|
LOG_WARNING => 1, |
12
|
|
|
|
|
|
|
LOG_ERROR => 1, |
13
|
|
|
|
|
|
|
LOG_NONE => 0, |
14
|
99
|
|
|
99
|
|
533
|
}; |
|
99
|
|
|
|
|
195
|
|
15
|
|
|
|
|
|
|
|
16
|
99
|
|
|
99
|
|
1967
|
use English qw(-no_match_vars); |
|
99
|
|
|
|
|
4318
|
|
|
99
|
|
|
|
|
758
|
|
17
|
99
|
|
|
99
|
|
57848
|
use UNIVERSAL::require; |
|
99
|
|
|
|
|
18719
|
|
|
99
|
|
|
|
|
792
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT = qw/LOG_DEBUG2 LOG_DEBUG LOG_INFO LOG_WARNING LOG_ERROR LOG_NONE/; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
85
|
|
|
85
|
1
|
50688
|
my ($class, %params) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $self = { |
25
|
85
|
100
|
|
|
|
579
|
verbosity => defined $params{verbosity} ? $params{verbosity} : LOG_INFO, |
26
|
|
|
|
|
|
|
}; |
27
|
85
|
|
|
|
|
250
|
bless $self, $class; |
28
|
|
|
|
|
|
|
|
29
|
85
|
|
|
|
|
181
|
my %backends; |
30
|
85
|
100
|
|
|
|
363
|
foreach ( |
31
|
74
|
|
|
|
|
290
|
$params{backends} ? @{$params{backends}} : 'Stderr' |
32
|
|
|
|
|
|
|
) { |
33
|
87
|
|
|
|
|
361
|
my $backend = ucfirst($_); |
34
|
87
|
50
|
|
|
|
421
|
next if $backends{$backend}; |
35
|
87
|
|
|
|
|
284
|
my $package = "FusionInventory::Agent::Logger::$backend"; |
36
|
87
|
|
|
|
|
808
|
$package->require(); |
37
|
87
|
50
|
|
|
|
43433
|
if ($EVAL_ERROR) { |
38
|
0
|
|
|
|
|
0
|
print STDERR |
39
|
|
|
|
|
|
|
"Failed to load Logger backend $backend: ($EVAL_ERROR)\n"; |
40
|
0
|
|
|
|
|
0
|
next; |
41
|
|
|
|
|
|
|
} |
42
|
87
|
|
|
|
|
414
|
$backends{$backend} = 1; |
43
|
|
|
|
|
|
|
|
44
|
87
|
|
|
|
|
552
|
$self->debug("Logger backend $backend initialised"); |
45
|
|
|
|
|
|
|
push |
46
|
87
|
|
|
|
|
171
|
@{$self->{backends}}, |
|
87
|
|
|
|
|
766
|
|
47
|
|
|
|
|
|
|
$package->new(%params); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
85
|
|
|
|
|
1192
|
$self->debug($FusionInventory::Agent::VERSION_STRING); |
51
|
|
|
|
|
|
|
|
52
|
85
|
|
|
|
|
457
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _log { |
56
|
2238
|
|
|
2238
|
|
6430
|
my ($self, %params) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# levels: debug2, debug, info, error, fault |
59
|
2238
|
|
50
|
|
|
5920
|
my $level = $params{level} || 'info'; |
60
|
2238
|
|
|
|
|
3524
|
my $message = $params{message}; |
61
|
|
|
|
|
|
|
|
62
|
2238
|
100
|
|
|
|
4869
|
return unless $message; |
63
|
|
|
|
|
|
|
|
64
|
2183
|
|
|
|
|
3607
|
chomp($message); |
65
|
|
|
|
|
|
|
|
66
|
2183
|
|
|
|
|
3211
|
foreach my $backend (@{$self->{backends}}) { |
|
2183
|
|
|
|
|
5810
|
|
67
|
2127
|
|
|
|
|
7101
|
$backend->addMessage ( |
68
|
|
|
|
|
|
|
level => $level, |
69
|
|
|
|
|
|
|
message => $message |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub debug2 { |
75
|
44
|
|
|
44
|
1
|
408
|
my ($self, $message) = @_; |
76
|
|
|
|
|
|
|
|
77
|
44
|
100
|
|
|
|
211
|
return unless $self->{verbosity} >= LOG_DEBUG2; |
78
|
1
|
|
|
|
|
3
|
$self->_log(level => 'debug2', message => $message); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub debug { |
82
|
271
|
|
|
271
|
1
|
3335
|
my ($self, $message) = @_; |
83
|
|
|
|
|
|
|
|
84
|
271
|
100
|
|
|
|
1569
|
return unless $self->{verbosity} >= LOG_DEBUG; |
85
|
154
|
|
|
|
|
469
|
$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
|
15053
|
my ($self, $message) = @_; |
103
|
|
|
|
|
|
|
|
104
|
2051
|
50
|
|
|
|
6105
|
return unless $self->{verbosity} >= LOG_INFO; |
105
|
2051
|
|
|
|
|
5359
|
$self->_log(level => 'info', message => $message); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub warning { |
109
|
3
|
|
|
3
|
1
|
1612
|
my ($self, $message) = @_; |
110
|
|
|
|
|
|
|
|
111
|
3
|
50
|
|
|
|
10
|
return unless $self->{verbosity} >= LOG_WARNING; |
112
|
3
|
|
|
|
|
10
|
$self->_log(level => 'warning', message => $message); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub error { |
116
|
29
|
|
|
29
|
1
|
1855
|
my ($self, $message) = @_; |
117
|
|
|
|
|
|
|
|
118
|
29
|
50
|
|
|
|
142
|
return unless $self->{verbosity} >= LOG_ERROR; |
119
|
29
|
|
|
|
|
148
|
$self->_log(level => 'error', message => $message); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
__END__ |