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