line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SolarWinds::LogMethods; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
49
|
use strict; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
164
|
|
4
|
5
|
|
|
5
|
|
36
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
4774
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=pod |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Net::SolarWinds::LogMethods - Passive logging interfcaes |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package MyClass; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use base qw(Net::SolarWinds::ConstructorHash Net::SolarWinds::LogMethods); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
1; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $pkg=new MyClass(key=>'value'); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This library provides a common logging interfcaes that expect Net::SolarWinds::Log or something that implements its features. It also assumes object instance is a hash with $self->{log} contains the logging object. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 OO Methods provided |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=over 4 |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=item * my $log=$self->get_log; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Returns the logging object if any |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
67
|
|
|
67
|
1
|
1908
|
sub get_log { $_[0]->{log} } |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item * $self->set_log(Net::SolarWinds::Log->new); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Sets the Chater::Log object, you can also set this in the constructor at object creation time. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
0
|
0
|
0
|
sub set_log { $_[0]->{log} = $_[1] } |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item * $self->log_error("Some error"); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This is a lazy man's wrapper function for |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $log=$self->get_log; |
52
|
|
|
|
|
|
|
$log->log_error("Some error") if $log; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub log_error { |
57
|
11
|
|
|
11
|
1
|
218
|
my ( $self, @args ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
11
|
|
|
|
|
43
|
my $log = $self->get_log; |
60
|
|
|
|
|
|
|
|
61
|
11
|
50
|
|
|
|
46
|
return 0 unless $log; |
62
|
|
|
|
|
|
|
|
63
|
11
|
100
|
|
|
|
45
|
return 1 unless $log->get_loglevel >= $log->LOG_ERROR; |
64
|
|
|
|
|
|
|
|
65
|
9
|
|
|
|
|
34
|
my @list = ('ERROR'); |
66
|
9
|
100
|
|
|
|
64
|
push @list, $self->log_header if $self->can('log_header'); |
67
|
|
|
|
|
|
|
|
68
|
9
|
|
|
|
|
41
|
return $log->write_to_log( @list, @args ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item * $log->log_die("Log this and die"); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Logs the given message then dies. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub log_die { |
78
|
2
|
|
|
2
|
1
|
14
|
my ( $self, @args ) = @_; |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
12
|
my $log = $self->get_log; |
81
|
2
|
|
|
|
|
10
|
my @list = ('DIE'); |
82
|
2
|
50
|
|
|
|
36
|
push @list, $self->log_header if $self->can('log_header'); |
83
|
|
|
|
|
|
|
|
84
|
2
|
|
|
|
|
22
|
my $string=$self->format_log(@list,@args); |
85
|
|
|
|
|
|
|
|
86
|
2
|
100
|
|
|
|
26
|
return die $string unless $log; |
87
|
|
|
|
|
|
|
|
88
|
1
|
50
|
|
|
|
14
|
return 1 unless $log->get_loglevel >= $log->LOG_ALWAYS; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
12
|
$log->write_to_log( @list, @args ); |
92
|
1
|
|
|
|
|
15
|
die $string; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub format_log { |
97
|
2
|
|
|
2
|
0
|
12
|
my ($self,@args)=@_; |
98
|
|
|
|
|
|
|
|
99
|
2
|
100
|
|
|
|
12
|
return join(' ',@args)."\n" unless $self->get_log; |
100
|
1
|
|
|
|
|
6
|
return $self->get_log->format_log(@args); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item * $self->log_always("Some msg"); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This is a lazy man's wrapper function for |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $log=$self->get_log; |
109
|
|
|
|
|
|
|
$log->log_always("Some msg") if $log; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub log_always { |
114
|
11
|
|
|
11
|
1
|
6964
|
my ( $self, @args ) = @_; |
115
|
|
|
|
|
|
|
|
116
|
11
|
|
|
|
|
50
|
my $log = $self->get_log; |
117
|
|
|
|
|
|
|
|
118
|
11
|
50
|
|
|
|
48
|
return 0 unless $log; |
119
|
|
|
|
|
|
|
|
120
|
11
|
50
|
|
|
|
50
|
return 1 unless $log->get_loglevel >= $log->LOG_ALWAYS; |
121
|
|
|
|
|
|
|
|
122
|
11
|
|
|
|
|
43
|
my @list = ('ALWAYS'); |
123
|
11
|
100
|
|
|
|
68
|
push @list, $self->log_header if $self->can('log_header'); |
124
|
|
|
|
|
|
|
|
125
|
11
|
|
|
|
|
53
|
return $log->write_to_log( @list, @args ); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * my $string=$self->log_header; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This is a stub function that allows a quick addin for logging, the string returned will be inserted after the log_level in the log file if this function is created. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * $self->log_warn("Some msg"); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This is a lazy man's wrapper function for: |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $log=$self->get_log; |
139
|
|
|
|
|
|
|
$log->log_warn("Some msg") if $log; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub log_warn { |
144
|
11
|
|
|
11
|
1
|
9906
|
my ( $self, @args ) = @_; |
145
|
|
|
|
|
|
|
|
146
|
11
|
|
|
|
|
39
|
my $log = $self->get_log; |
147
|
|
|
|
|
|
|
|
148
|
11
|
50
|
|
|
|
44
|
return 0 unless $log; |
149
|
|
|
|
|
|
|
|
150
|
11
|
100
|
|
|
|
55
|
return 1 unless $log->get_loglevel >= $log->LOG_WARN; |
151
|
7
|
|
|
|
|
26
|
my @list = ('WARN'); |
152
|
7
|
100
|
|
|
|
49
|
push @list, $self->log_header if $self->can('log_header'); |
153
|
|
|
|
|
|
|
|
154
|
7
|
|
|
|
|
32
|
return $log->write_to_log( @list, @args ); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * $self->log_info("Some msg"); |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This is a lazy man's wrapper function for: |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my $log=$self->get_log; |
162
|
|
|
|
|
|
|
$log->log_info("Some msg") if $log; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub log_info { |
167
|
12
|
|
|
12
|
1
|
9043
|
my ( $self, @args ) = @_; |
168
|
|
|
|
|
|
|
|
169
|
12
|
|
|
|
|
49
|
my $log = $self->get_log; |
170
|
|
|
|
|
|
|
|
171
|
12
|
50
|
|
|
|
49
|
return 0 unless $log; |
172
|
|
|
|
|
|
|
|
173
|
12
|
100
|
|
|
|
53
|
return 1 unless $log->get_loglevel >= $log->LOG_INFO; |
174
|
6
|
|
|
|
|
25
|
my @list = ('INFO'); |
175
|
6
|
100
|
|
|
|
46
|
push @list, $self->log_header if $self->can('log_header'); |
176
|
|
|
|
|
|
|
|
177
|
6
|
|
|
|
|
26
|
return $log->write_to_log( @list, @args ); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * $self->log_debug("Some msg"); |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This is a lazy man's wrapper function for: |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
my $log=$self->get_log; |
185
|
|
|
|
|
|
|
$log->log_debug("Some msg") if $log; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub log_debug { |
190
|
15
|
|
|
15
|
1
|
7971
|
my ( $self, @args ) = @_; |
191
|
|
|
|
|
|
|
|
192
|
15
|
|
|
|
|
64
|
my $log = $self->get_log; |
193
|
|
|
|
|
|
|
|
194
|
15
|
100
|
|
|
|
71
|
return 0 unless $log; |
195
|
|
|
|
|
|
|
|
196
|
11
|
100
|
|
|
|
53
|
return 1 unless $log->get_loglevel >= $log->LOG_DEBUG; |
197
|
|
|
|
|
|
|
|
198
|
3
|
|
|
|
|
14
|
my @list = ('DEBUG'); |
199
|
3
|
100
|
|
|
|
23
|
push @list, $self->log_header if $self->can('log_header'); |
200
|
|
|
|
|
|
|
|
201
|
3
|
|
|
|
|
13
|
return $log->write_to_log( @list, @args ); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=back |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 AUTHOR |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Michael Shipper |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
1; |