line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SolarWinds::LogMethods; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
39
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
138
|
|
4
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
2876
|
|
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
|
1105
|
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
|
163
|
my ( $self, @args ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
11
|
|
|
|
|
28
|
my $log = $self->get_log; |
60
|
|
|
|
|
|
|
|
61
|
11
|
50
|
|
|
|
34
|
return 0 unless $log; |
62
|
|
|
|
|
|
|
|
63
|
11
|
100
|
|
|
|
30
|
return 1 unless $log->get_loglevel >= $log->LOG_ERROR; |
64
|
|
|
|
|
|
|
|
65
|
9
|
|
|
|
|
20
|
my @list = ('ERROR'); |
66
|
9
|
100
|
|
|
|
47
|
push @list, $self->log_header if $self->can('log_header'); |
67
|
|
|
|
|
|
|
|
68
|
9
|
|
|
|
|
29
|
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
|
6
|
my ( $self, @args ) = @_; |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
6
|
my $log = $self->get_log; |
81
|
2
|
|
|
|
|
5
|
my @list = ('DIE'); |
82
|
2
|
50
|
|
|
|
18
|
push @list, $self->log_header if $self->can('log_header'); |
83
|
|
|
|
|
|
|
|
84
|
2
|
|
|
|
|
11
|
my $string=$self->format_log(@list,@args); |
85
|
|
|
|
|
|
|
|
86
|
2
|
100
|
|
|
|
9
|
return die $string unless $log; |
87
|
|
|
|
|
|
|
|
88
|
1
|
50
|
|
|
|
4
|
return 1 unless $log->get_loglevel >= $log->LOG_ALWAYS; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
5
|
$log->write_to_log( @list, @args ); |
92
|
1
|
|
|
|
|
6
|
die $string; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub format_log { |
97
|
2
|
|
|
2
|
0
|
5
|
my ($self,@args)=@_; |
98
|
|
|
|
|
|
|
|
99
|
2
|
100
|
|
|
|
6
|
return join(' ',@args)."\n" unless $self->get_log; |
100
|
1
|
|
|
|
|
3
|
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
|
5929
|
my ( $self, @args ) = @_; |
115
|
|
|
|
|
|
|
|
116
|
11
|
|
|
|
|
33
|
my $log = $self->get_log; |
117
|
|
|
|
|
|
|
|
118
|
11
|
50
|
|
|
|
33
|
return 0 unless $log; |
119
|
|
|
|
|
|
|
|
120
|
11
|
50
|
|
|
|
38
|
return 1 unless $log->get_loglevel >= $log->LOG_ALWAYS; |
121
|
|
|
|
|
|
|
|
122
|
11
|
|
|
|
|
29
|
my @list = ('ALWAYS'); |
123
|
11
|
100
|
|
|
|
50
|
push @list, $self->log_header if $self->can('log_header'); |
124
|
|
|
|
|
|
|
|
125
|
11
|
|
|
|
|
35
|
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
|
8210
|
my ( $self, @args ) = @_; |
145
|
|
|
|
|
|
|
|
146
|
11
|
|
|
|
|
32
|
my $log = $self->get_log; |
147
|
|
|
|
|
|
|
|
148
|
11
|
50
|
|
|
|
31
|
return 0 unless $log; |
149
|
|
|
|
|
|
|
|
150
|
11
|
100
|
|
|
|
36
|
return 1 unless $log->get_loglevel >= $log->LOG_WARN; |
151
|
7
|
|
|
|
|
17
|
my @list = ('WARN'); |
152
|
7
|
100
|
|
|
|
35
|
push @list, $self->log_header if $self->can('log_header'); |
153
|
|
|
|
|
|
|
|
154
|
7
|
|
|
|
|
21
|
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
|
7155
|
my ( $self, @args ) = @_; |
168
|
|
|
|
|
|
|
|
169
|
12
|
|
|
|
|
34
|
my $log = $self->get_log; |
170
|
|
|
|
|
|
|
|
171
|
12
|
50
|
|
|
|
37
|
return 0 unless $log; |
172
|
|
|
|
|
|
|
|
173
|
12
|
100
|
|
|
|
40
|
return 1 unless $log->get_loglevel >= $log->LOG_INFO; |
174
|
6
|
|
|
|
|
14
|
my @list = ('INFO'); |
175
|
6
|
100
|
|
|
|
35
|
push @list, $self->log_header if $self->can('log_header'); |
176
|
|
|
|
|
|
|
|
177
|
6
|
|
|
|
|
18
|
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
|
6428
|
my ( $self, @args ) = @_; |
191
|
|
|
|
|
|
|
|
192
|
15
|
|
|
|
|
41
|
my $log = $self->get_log; |
193
|
|
|
|
|
|
|
|
194
|
15
|
100
|
|
|
|
58
|
return 0 unless $log; |
195
|
|
|
|
|
|
|
|
196
|
11
|
100
|
|
|
|
36
|
return 1 unless $log->get_loglevel >= $log->LOG_DEBUG; |
197
|
|
|
|
|
|
|
|
198
|
3
|
|
|
|
|
10
|
my @list = ('DEBUG'); |
199
|
3
|
100
|
|
|
|
16
|
push @list, $self->log_header if $self->can('log_header'); |
200
|
|
|
|
|
|
|
|
201
|
3
|
|
|
|
|
9
|
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; |