line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Logger; |
2
|
|
|
|
|
|
|
|
3
|
30
|
|
|
30
|
|
3631566
|
use strict; |
|
30
|
|
|
|
|
58
|
|
|
30
|
|
|
|
|
1144
|
|
4
|
30
|
|
|
30
|
|
144
|
use warnings; |
|
30
|
|
|
|
|
40
|
|
|
30
|
|
|
|
|
1078
|
|
5
|
30
|
|
|
30
|
|
143
|
use base qw/Exporter/; |
|
30
|
|
|
|
|
81
|
|
|
30
|
|
|
|
|
3590
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
30
|
|
|
|
|
12030
|
LOG_DEBUG2 => 5, |
9
|
|
|
|
|
|
|
LOG_DEBUG => 4, |
10
|
|
|
|
|
|
|
LOG_INFO => 3, |
11
|
|
|
|
|
|
|
LOG_WARNING => 1, |
12
|
|
|
|
|
|
|
LOG_ERROR => 1, |
13
|
|
|
|
|
|
|
LOG_NONE => 0, |
14
|
30
|
|
|
30
|
|
153
|
}; |
|
30
|
|
|
|
|
43
|
|
15
|
|
|
|
|
|
|
|
16
|
30
|
|
|
30
|
|
163
|
use English qw(-no_match_vars); |
|
30
|
|
|
|
|
39
|
|
|
30
|
|
|
|
|
258
|
|
17
|
30
|
|
|
30
|
|
17745
|
use UNIVERSAL::require; |
|
30
|
|
|
|
|
12337
|
|
|
30
|
|
|
|
|
326
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT = qw/LOG_DEBUG2 LOG_DEBUG LOG_INFO LOG_WARNING LOG_ERROR LOG_NONE/; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
11
|
|
|
11
|
1
|
5738
|
my ($class, %params) = @_; |
23
|
|
|
|
|
|
|
|
24
|
11
|
50
|
|
|
|
63
|
my $self = { |
25
|
|
|
|
|
|
|
verbosity => defined $params{verbosity} ? $params{verbosity} : LOG_INFO, |
26
|
|
|
|
|
|
|
}; |
27
|
11
|
|
|
|
|
28
|
bless $self, $class; |
28
|
|
|
|
|
|
|
|
29
|
11
|
|
|
|
|
17
|
my %backends; |
30
|
11
|
100
|
|
|
|
43
|
foreach ( |
31
|
9
|
|
|
|
|
35
|
$params{backends} ? @{$params{backends}} : 'Stderr' |
32
|
|
|
|
|
|
|
) { |
33
|
11
|
|
|
|
|
35
|
my $backend = ucfirst($_); |
34
|
11
|
50
|
|
|
|
41
|
next if $backends{$backend}; |
35
|
11
|
|
|
|
|
30
|
my $package = "FusionInventory::Agent::Logger::$backend"; |
36
|
11
|
|
|
|
|
82
|
$package->require(); |
37
|
11
|
50
|
|
|
|
3825
|
if ($EVAL_ERROR) { |
38
|
0
|
|
|
|
|
0
|
print STDERR |
39
|
|
|
|
|
|
|
"Failed to load Logger backend $backend: ($EVAL_ERROR)\n"; |
40
|
0
|
|
|
|
|
0
|
next; |
41
|
|
|
|
|
|
|
} |
42
|
11
|
|
|
|
|
33
|
$backends{$backend} = 1; |
43
|
|
|
|
|
|
|
|
44
|
11
|
|
|
|
|
147
|
$self->debug("Logger backend $backend initialised"); |
45
|
11
|
|
|
|
|
103
|
push |
46
|
11
|
|
|
|
|
23
|
@{$self->{backends}}, |
47
|
|
|
|
|
|
|
$package->new(%params); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
11
|
|
|
|
|
89
|
$self->debug($FusionInventory::Agent::VERSION_STRING); |
51
|
|
|
|
|
|
|
|
52
|
11
|
|
|
|
|
64
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _log { |
56
|
29
|
|
|
29
|
|
267
|
my ($self, %params) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# levels: debug2, debug, info, error, fault |
59
|
29
|
|
50
|
|
|
176
|
my $level = $params{level} || 'info'; |
60
|
29
|
|
|
|
|
64
|
my $message = $params{message}; |
61
|
|
|
|
|
|
|
|
62
|
29
|
50
|
|
|
|
77
|
return unless $message; |
63
|
|
|
|
|
|
|
|
64
|
29
|
|
|
|
|
107
|
chomp($message); |
65
|
|
|
|
|
|
|
|
66
|
29
|
|
|
|
|
42
|
foreach my $backend (@{$self->{backends}}) { |
|
29
|
|
|
|
|
172
|
|
67
|
29
|
|
|
|
|
246
|
$backend->addMessage ( |
68
|
|
|
|
|
|
|
level => $level, |
69
|
|
|
|
|
|
|
message => $message |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub debug2 { |
75
|
19
|
|
|
19
|
1
|
56
|
my ($self, $message) = @_; |
76
|
|
|
|
|
|
|
|
77
|
19
|
50
|
|
|
|
95
|
return unless $self->{verbosity} >= LOG_DEBUG2; |
78
|
0
|
|
|
|
|
0
|
$self->_log(level => 'debug2', message => $message); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub debug { |
82
|
39
|
|
|
39
|
1
|
96
|
my ($self, $message) = @_; |
83
|
|
|
|
|
|
|
|
84
|
39
|
50
|
|
|
|
192
|
return unless $self->{verbosity} >= LOG_DEBUG; |
85
|
0
|
|
|
|
|
0
|
$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
|
0
|
|
|
|
|
0
|
$self->_log( |
96
|
|
|
|
|
|
|
level => 'debug', |
97
|
|
|
|
|
|
|
message => sprintf('- %s: %s', $params{action}, $status) |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub info { |
102
|
0
|
|
|
0
|
1
|
0
|
my ($self, $message) = @_; |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
0
|
return unless $self->{verbosity} >= LOG_INFO; |
105
|
0
|
|
|
|
|
0
|
$self->_log(level => 'info', message => $message); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub warning { |
109
|
0
|
|
|
0
|
1
|
0
|
my ($self, $message) = @_; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
0
|
return unless $self->{verbosity} >= LOG_WARNING; |
112
|
0
|
|
|
|
|
0
|
$self->_log(level => 'warning', message => $message); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub error { |
116
|
29
|
|
|
29
|
1
|
228
|
my ($self, $message) = @_; |
117
|
|
|
|
|
|
|
|
118
|
29
|
50
|
|
|
|
145
|
return unless $self->{verbosity} >= LOG_ERROR; |
119
|
29
|
|
|
|
|
218
|
$self->_log(level => 'error', message => $message); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
__END__ |