line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- cperl -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 1997-2006 Samuel MOUNIEE |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This file is part of Log::Simple. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Log::Simple is free software; you can redistribute it and/or modify |
8
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
9
|
|
|
|
|
|
|
# the Free Software Foundation; version 2 of the License. |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Log::Simple is distributed in the hope that it will be useful, |
12
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
|
|
|
|
# GNU General Public License for more details. |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
17
|
|
|
|
|
|
|
# along with Log::Simple ; if not, write to the Free Software |
18
|
|
|
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
package Log::Simple; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
3
|
|
63795
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
104
|
|
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
3
|
|
15
|
no strict qw( refs ); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
71
|
|
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
3
|
|
14
|
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK ); |
|
3
|
|
|
|
|
192
|
|
|
3
|
|
|
|
|
342
|
|
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
3
|
|
15
|
use Exporter; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2234
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
( $VERSION ) = '$Revision: 1.8 $ ' =~ /\$Revision:\s+([^\s]+)/; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
34
|
|
|
|
|
|
|
@EXPORT_OK = qw( logger time_track set_logger set_local_logger ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my ( $LOGLEVEL, $CONFESS ) = ( 0, 0 ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $LOGGER = { |
40
|
|
|
|
|
|
|
Default => [ \&std_logger ] |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Log::Simple - Basic runtime logger |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
use Log::Simple ( 6 ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
set_logger( 2, sub { print join ( "", @_, "\n") } ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
set_logger( 3, sub { print "$_\n" for @_ } ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
logger( 1, "hello" ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
logger( 7, "this", $message, "never appears" ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
logger( 2, "this", "message", "will", "be", "printed", "without", "space" ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
logger( 3, "this", "message", "will", "be", "printed", "a", "word", "by", "line" ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
package My::Example; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
use Log::Simple ( 7 ); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
logger( 7, "this message appears" ); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
set_local_logger( 3, sub { print join ( "", @_, "too\n") } ); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
logger( 2, "this", "message", "will", "be", "printed", "without", "space" ); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
logger( 3, "this", "message", "will", "be", "printed", "without", "space" ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 DESCRIPTION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 External Functions |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=over 4 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item logger( $level, @messages ) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
log informations |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
sub logger { |
98
|
6
|
|
|
6
|
1
|
104
|
my $cllpkg = (caller(0))[0]; |
99
|
|
|
|
|
|
|
|
100
|
6
|
|
|
|
|
14
|
my $i = $cllpkg . "::LOGLEVEL"; |
101
|
|
|
|
|
|
|
|
102
|
6
|
50
|
|
|
|
21
|
$cllpkg = "Default" unless defined( $LOGGER->{$cllpkg} ); |
103
|
|
|
|
|
|
|
|
104
|
6
|
100
|
66
|
|
|
7
|
if ( ( defined( ${$i} ) && ( $_[0] <= ${$i} ) ) || |
|
6
|
|
33
|
|
|
32
|
|
|
6
|
|
66
|
|
|
49
|
|
|
2
|
|
|
|
|
15
|
|
105
|
|
|
|
|
|
|
(!defined( ${$i} ) && ( $_[0] <= $LOGLEVEL ) ) ) { |
106
|
4
|
100
|
|
|
|
26
|
return $LOGGER->{$cllpkg}->[$_[0]+1]->( @_ ) |
107
|
|
|
|
|
|
|
if ref( $LOGGER->{$cllpkg}->[$_[0]+1] ) eq "CODE"; |
108
|
|
|
|
|
|
|
|
109
|
2
|
50
|
|
|
|
19
|
return $LOGGER->{$cllpkg}->[0]->( @_ ) |
110
|
|
|
|
|
|
|
if ref( $LOGGER->{$cllpkg}->[0] ) eq "CODE"; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
return std_logger( @_ ); |
113
|
|
|
|
|
|
|
} |
114
|
2
|
|
|
|
|
8
|
return -1; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=pod |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item set_logger ( $level , $callback ) |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Install an generic Logger. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
sub set_logger($&) { |
126
|
2
|
|
|
2
|
1
|
15
|
my( $level, $code ) = @_; |
127
|
|
|
|
|
|
|
|
128
|
2
|
50
|
|
|
|
6
|
$level = -1 if $level < 0; |
129
|
|
|
|
|
|
|
|
130
|
2
|
|
|
|
|
8
|
$LOGGER->{Default}->[$level+1] = $code; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=pod |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item set_local_logger ( $level , $callback ) |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
install an local Logger. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
sub set_local_logger($&) { |
142
|
0
|
|
|
0
|
1
|
0
|
my( $level, $code ) = @_; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
0
|
my $cllpkg = (caller(0))[0]; |
145
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
0
|
$level = -1 if $level < 0; |
147
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
0
|
$LOGGER->{$cllpkg} = [ \&std_logger ] |
149
|
|
|
|
|
|
|
unless defined( $LOGGER->{$cllpkg} ); |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
0
|
$LOGGER->{$cllpkg}->[$level+1] = $code; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=pod |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=back |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 Internal Functions |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=over 4 |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item std_logger( @messages ) |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
log information to STDERR |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
sub std_logger { |
169
|
3
|
|
|
3
|
1
|
6
|
my $l = shift; |
170
|
3
|
|
|
|
|
229
|
print STDERR "$l : " . join( " + ", @_, "\n" ); |
171
|
3
|
50
|
|
|
|
32
|
return $l unless $CONFESS; |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
0
|
my ( $i, @tmp ) = ( 0 ); |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
0
|
while( @tmp = caller( $i++ ) ) { |
176
|
0
|
|
|
|
|
0
|
print STDERR "\t> " . join( " + ", grep { defined $_ } @tmp, "\n" ); |
|
0
|
|
|
|
|
0
|
|
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
0
|
return $l; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=pod |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item time_track( ) |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
callback which permit to timestamp messages. |
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
sub time_track |
191
|
|
|
|
|
|
|
{ |
192
|
1
|
|
|
1
|
1
|
14
|
Log::Simple::std_logger( "time_track", time(), ( caller ) ) |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=pod |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item import |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Set the Logging/Debug level and export external functions |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
203
|
|
|
|
|
|
|
sub import($$) |
204
|
|
|
|
|
|
|
{ |
205
|
3
|
|
|
3
|
|
25
|
my @tmp = @EXPORT_OK; |
206
|
3
|
|
|
|
|
17
|
my $cllpkg = (caller(0))[0]; |
207
|
3
|
|
|
|
|
8
|
my $DBG = $cllpkg . "::LOGLEVEL"; |
208
|
3
|
|
|
|
|
6
|
my $dbg = $cllpkg . "::logger"; |
209
|
|
|
|
|
|
|
|
210
|
3
|
|
|
|
|
6
|
${$DBG} = $_[1]; |
|
3
|
|
|
|
|
13
|
|
211
|
|
|
|
|
|
|
|
212
|
3
|
50
|
|
|
|
14
|
if ( $_[1] > 0 ) |
213
|
|
|
|
|
|
|
{ |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
else |
216
|
|
|
|
|
|
|
{ |
217
|
0
|
|
|
|
|
0
|
shift @tmp; |
218
|
0
|
|
|
0
|
|
0
|
*{$dbg} = sub { }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
219
|
|
|
|
|
|
|
} |
220
|
3
|
|
|
|
|
350
|
Log::Simple->export_to_level( 1, undef, @tmp ); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
__END__ |