| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package TRD::DebugLog; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#use warnings; |
|
4
|
1
|
|
|
1
|
|
48118
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
1264
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
TRD::DebugLog - debug log |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.0.9 |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.0.9'; |
|
17
|
|
|
|
|
|
|
our $enabled = 0; |
|
18
|
|
|
|
|
|
|
our $timestamp = 1; |
|
19
|
|
|
|
|
|
|
our $file = undef; |
|
20
|
|
|
|
|
|
|
our $timeformat = 'YYYY/MM/DD HH24:MI:SS '; |
|
21
|
|
|
|
|
|
|
our $cutpackage = 'main'; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Quick summary of what the module does. |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Perhaps a little code snippet. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use TRD::DebugLog; |
|
30
|
|
|
|
|
|
|
$TRD::DebugLog::enabled = 1; |
|
31
|
|
|
|
|
|
|
dlog( "this is debug log" ); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
or |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use TRD::DebugLog { enabled=>1, timeformat='YYYY-MM-DD HH24:MI:SS' }; |
|
36
|
|
|
|
|
|
|
dlog( "this is debug log" ); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 EXPORT |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
A list of functions that can be exported. You can delete this section |
|
41
|
|
|
|
|
|
|
if you don't export anything, such as for a purely object-oriented module. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 dlog( log ) |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
show debug log. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$TRD::DebugLog::enabled |
|
50
|
|
|
|
|
|
|
default: 0 |
|
51
|
|
|
|
|
|
|
= 1 : enable debug log |
|
52
|
|
|
|
|
|
|
= 0 : disable debug log |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$TRD::DebugLog::timestamp |
|
55
|
|
|
|
|
|
|
default: 1 |
|
56
|
|
|
|
|
|
|
= 1 : show timestamp enable |
|
57
|
|
|
|
|
|
|
= 0 : show timestamp disable |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$TRD::DebugLog::file |
|
60
|
|
|
|
|
|
|
default: undef |
|
61
|
|
|
|
|
|
|
debug log append to file |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$TRD::DebugLog::timeformat |
|
64
|
|
|
|
|
|
|
default: YYYY/MM/DD HH24:MI:SS |
|
65
|
|
|
|
|
|
|
YYYY : 4digit Year |
|
66
|
|
|
|
|
|
|
YY : 2digit Year |
|
67
|
|
|
|
|
|
|
MM : 2digit Month |
|
68
|
|
|
|
|
|
|
DD : 2digit Day |
|
69
|
|
|
|
|
|
|
HH24 : 24hour 2digit Hour |
|
70
|
|
|
|
|
|
|
MI : 2digit Min |
|
71
|
|
|
|
|
|
|
SS : 2digit Sec |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$TRD::DebugLog::cutpackage |
|
74
|
|
|
|
|
|
|
default: main (cut 'main::' only) |
|
75
|
|
|
|
|
|
|
: all |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#====================================================================== |
|
80
|
|
|
|
|
|
|
sub dlog($) |
|
81
|
|
|
|
|
|
|
{ |
|
82
|
0
|
|
|
0
|
1
|
0
|
my( $log ) = @_; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
0
|
my $buff = undef; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
0
|
if( $TRD::DebugLog::enabled ){ |
|
87
|
0
|
|
|
|
|
0
|
my( $source, $line, $func ); |
|
88
|
0
|
|
|
|
|
0
|
( $source, $line ) = (caller 0)[1,2]; |
|
89
|
0
|
|
|
|
|
0
|
( $func ) = (caller 1)[3]; |
|
90
|
0
|
0
|
|
|
|
0
|
if( $cutpackage eq 'main' ){ |
|
|
|
0
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
$func =~s/^main:://; |
|
92
|
|
|
|
|
|
|
} elsif( $cutpackage eq 'all' ){ |
|
93
|
0
|
|
|
|
|
0
|
$func = ( split( '::', $func ) )[-1]; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
$buff = "${source}(${line}):${func}:${log}\n"; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
0
|
if( $TRD::DebugLog::timestamp ){ |
|
99
|
0
|
|
|
|
|
0
|
my $timestr = &getTimeStr(); |
|
100
|
0
|
|
|
|
|
0
|
$buff = $timestr. $buff; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
0
|
if( $TRD::DebugLog::file ){ |
|
104
|
0
|
0
|
|
|
|
0
|
open( my $fh, ">>", "${file}" ) || die $!; |
|
105
|
0
|
|
|
|
|
0
|
print $fh $buff; |
|
106
|
0
|
|
|
|
|
0
|
close( $fh ); |
|
107
|
|
|
|
|
|
|
} else { |
|
108
|
0
|
|
|
|
|
0
|
print STDERR $buff; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
} |
|
111
|
0
|
|
|
|
|
0
|
return $buff; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 Exception( log ) |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
show exception log |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
|
119
|
|
|
|
|
|
|
#====================================================================== |
|
120
|
|
|
|
|
|
|
sub Exception |
|
121
|
|
|
|
|
|
|
{ |
|
122
|
0
|
|
|
0
|
1
|
0
|
my( $log ) = @_; |
|
123
|
0
|
|
|
|
|
0
|
my( $p, $f, $l ) = caller(0); |
|
124
|
0
|
|
|
|
|
0
|
my( $s ) = (caller(1))[3]; |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
0
|
print STDERR "TRD::DebugLog::Exception: ${log}\n"; |
|
127
|
0
|
|
|
|
|
0
|
my $i=0; |
|
128
|
0
|
|
|
|
|
0
|
while(1){ |
|
129
|
0
|
|
|
|
|
0
|
my( $package, $filename, $line ) = (caller $i)[0,1,2]; |
|
130
|
0
|
|
|
|
|
0
|
my( $subroutine ) = (caller $i+1)[3]; |
|
131
|
0
|
|
|
|
|
0
|
$package .= '::'; |
|
132
|
0
|
0
|
|
|
|
0
|
$package = '' if( $package eq 'main::' ); |
|
133
|
0
|
|
|
|
|
0
|
print STDERR "\tat ${filename}(${line})\t${package}${subroutine}\n"; |
|
134
|
0
|
|
|
|
|
0
|
$i++; |
|
135
|
0
|
0
|
|
|
|
0
|
if( !defined( $subroutine ) ){ |
|
136
|
0
|
|
|
|
|
0
|
last; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 getTimeStr( time ) |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
make timestr |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my $timestr = &TRD::DebugLog::getTimeStr( time ); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#====================================================================== |
|
150
|
|
|
|
|
|
|
sub getTimeStr |
|
151
|
|
|
|
|
|
|
{ |
|
152
|
0
|
0
|
|
0
|
1
|
0
|
my $time = (@_) ? shift : time; |
|
153
|
0
|
|
|
|
|
0
|
my( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = |
|
154
|
|
|
|
|
|
|
localtime( $time ); |
|
155
|
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
0
|
my $timestr = $timeformat; |
|
157
|
0
|
|
|
|
|
0
|
$timestr=~s/YYYY/sprintf( "%04d", $year + 1900)/eg; |
|
|
0
|
|
|
|
|
0
|
|
|
158
|
0
|
|
|
|
|
0
|
$timestr=~s/YY/sprintf( "%02d", $year - 100 )/eg; |
|
|
0
|
|
|
|
|
0
|
|
|
159
|
0
|
|
|
|
|
0
|
$timestr=~s/MM/sprintf( "%02d", $mon + 1 )/eg; |
|
|
0
|
|
|
|
|
0
|
|
|
160
|
0
|
|
|
|
|
0
|
$timestr=~s/DD/sprintf( "%02d", $mday )/eg; |
|
|
0
|
|
|
|
|
0
|
|
|
161
|
0
|
|
|
|
|
0
|
$timestr=~s/HH24/sprintf( "%02d", $hour )/eg; |
|
|
0
|
|
|
|
|
0
|
|
|
162
|
0
|
|
|
|
|
0
|
$timestr=~s/MI/sprintf( "%02d", $min )/eg; |
|
|
0
|
|
|
|
|
0
|
|
|
163
|
0
|
|
|
|
|
0
|
$timestr=~s/SS/sprintf( "%02d", $sec )/eg; |
|
|
0
|
|
|
|
|
0
|
|
|
164
|
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
0
|
return $timestr; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 import |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
import module |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
|
173
|
|
|
|
|
|
|
#====================================================================== |
|
174
|
|
|
|
|
|
|
sub import |
|
175
|
|
|
|
|
|
|
{ |
|
176
|
1
|
|
|
1
|
|
11
|
my $package = shift; |
|
177
|
1
|
|
|
|
|
12
|
my $callerpkg = (caller(0))[0]; |
|
178
|
1
|
|
|
1
|
|
9
|
no strict qw(refs); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
285
|
|
|
179
|
1
|
|
|
|
|
3
|
*{"$callerpkg\::dlog"} = *{"TRD\::DebugLog\::dlog"}; |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
4
|
|
|
180
|
|
|
|
|
|
|
|
|
181
|
1
|
|
|
|
|
4
|
my( @param ) = @_; |
|
182
|
|
|
|
|
|
|
|
|
183
|
1
|
|
|
|
|
14
|
foreach my $p ( @param ){ |
|
184
|
0
|
|
|
|
|
|
foreach my $key ( keys(%{$p}) ){ |
|
|
0
|
|
|
|
|
|
|
|
185
|
0
|
0
|
|
|
|
|
if( $key eq 'enabled' ){ |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
$enabled = $p->{$key}; |
|
187
|
|
|
|
|
|
|
} elsif( $key eq 'timestamp' ){ |
|
188
|
0
|
|
|
|
|
|
$timestamp = $p->{$key}; |
|
189
|
|
|
|
|
|
|
} elsif( $key eq 'file' ){ |
|
190
|
0
|
|
|
|
|
|
$file = $p->{$key}; |
|
191
|
0
|
0
|
|
|
|
|
$file = undef if( $file eq '' ); |
|
192
|
|
|
|
|
|
|
} elsif( $key eq 'timeformat' ){ |
|
193
|
0
|
|
|
|
|
|
$timeformat = $p->{$key}; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 AUTHOR |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Takuya Ichikawa, C<< >> |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 BUGS |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
206
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
207
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 SUPPORT |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
perldoc TRD::DebugLog |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
You can also look for information at: |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=over 4 |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
L |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
L |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
L |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item * Search CPAN |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
L |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=back |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Copyright 2008 Takuya Ichikawa, all rights reserved. |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
250
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=cut |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
1; # End of TRD::DebugLog |