| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
7
|
|
|
7
|
|
1367620
|
use strict; |
|
|
7
|
|
|
|
|
35
|
|
|
|
7
|
|
|
|
|
186
|
|
|
2
|
7
|
|
|
7
|
|
34
|
use warnings; |
|
|
7
|
|
|
|
|
11
|
|
|
|
7
|
|
|
|
|
354
|
|
|
3
|
|
|
|
|
|
|
# vim: set ts=8 sts=4 sw=4 tw=115 et : |
|
4
|
|
|
|
|
|
|
# ABSTRACT: Logging to date/time stamped files |
|
5
|
|
|
|
|
|
|
# KEYWORDS: log logging output file timestamp date rolling rotate |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.21'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use File::Basename qw(fileparse); |
|
10
|
7
|
|
|
7
|
|
40
|
use File::Spec::Functions qw(catfile); |
|
|
7
|
|
|
|
|
11
|
|
|
|
7
|
|
|
|
|
478
|
|
|
11
|
7
|
|
|
7
|
|
2303
|
use POSIX qw(strftime); |
|
|
7
|
|
|
|
|
4217
|
|
|
|
7
|
|
|
|
|
352
|
|
|
12
|
7
|
|
|
7
|
|
40
|
|
|
|
7
|
|
|
|
|
21
|
|
|
|
7
|
|
|
|
|
60
|
|
|
13
|
|
|
|
|
|
|
use Log::Dispatch::File 2.38; |
|
14
|
7
|
|
|
7
|
|
11176
|
use parent 'Log::Dispatch::File'; |
|
|
7
|
|
|
|
|
634228
|
|
|
|
7
|
|
|
|
|
269
|
|
|
15
|
7
|
|
|
7
|
|
55
|
|
|
|
7
|
|
|
|
|
14
|
|
|
|
7
|
|
|
|
|
59
|
|
|
16
|
|
|
|
|
|
|
use Params::ValidationCompiler qw(validation_for); |
|
17
|
7
|
|
|
7
|
|
422
|
|
|
|
7
|
|
|
|
|
25
|
|
|
|
7
|
|
|
|
|
336
|
|
|
18
|
|
|
|
|
|
|
use Specio::Library::Builtins; |
|
19
|
7
|
|
|
7
|
|
37
|
use Specio::Library::String; |
|
|
7
|
|
|
|
|
15
|
|
|
|
7
|
|
|
|
|
77
|
|
|
20
|
7
|
|
|
7
|
|
54407
|
use Specio::Declare 0.48; |
|
|
7
|
|
|
|
|
17
|
|
|
|
7
|
|
|
|
|
55
|
|
|
21
|
7
|
|
|
7
|
|
12424
|
|
|
|
7
|
|
|
|
|
180
|
|
|
|
7
|
|
|
|
|
52
|
|
|
22
|
|
|
|
|
|
|
use namespace::clean 0.19; |
|
23
|
7
|
|
|
7
|
|
1293
|
|
|
|
7
|
|
|
|
|
127
|
|
|
|
7
|
|
|
|
|
95
|
|
|
24
|
|
|
|
|
|
|
enum( |
|
25
|
|
|
|
|
|
|
'TimeFunctions', |
|
26
|
|
|
|
|
|
|
values => [qw(localtime gmtime)], |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
{ |
|
30
|
|
|
|
|
|
|
my $self = shift; |
|
31
|
|
|
|
|
|
|
|
|
32
|
13
|
|
|
13
|
|
48135
|
$self->SUPER::_basic_init(@_); |
|
33
|
|
|
|
|
|
|
|
|
34
|
13
|
|
|
|
|
80
|
my $validator = validation_for( |
|
35
|
|
|
|
|
|
|
params => { |
|
36
|
13
|
|
|
|
|
1190
|
stamp_fmt => { |
|
37
|
|
|
|
|
|
|
type => t('SimpleStr'), |
|
38
|
|
|
|
|
|
|
default => '%Y%m%d', |
|
39
|
|
|
|
|
|
|
}, |
|
40
|
|
|
|
|
|
|
stamp_sep => { |
|
41
|
|
|
|
|
|
|
type => t('SimpleStr'), |
|
42
|
|
|
|
|
|
|
default => '-', |
|
43
|
|
|
|
|
|
|
}, |
|
44
|
|
|
|
|
|
|
time_function => { |
|
45
|
|
|
|
|
|
|
type => t('TimeFunctions'), |
|
46
|
|
|
|
|
|
|
default => 'localtime', |
|
47
|
|
|
|
|
|
|
}, |
|
48
|
|
|
|
|
|
|
}, |
|
49
|
|
|
|
|
|
|
slurpy => 1, |
|
50
|
|
|
|
|
|
|
); |
|
51
|
|
|
|
|
|
|
my %p = $validator->(@_); |
|
52
|
|
|
|
|
|
|
|
|
53
|
13
|
|
|
|
|
23434
|
$self->{stamp_fmt} = $p{stamp_fmt}; |
|
54
|
|
|
|
|
|
|
$self->{stamp_sep} = $p{stamp_sep}; |
|
55
|
12
|
|
|
|
|
346
|
$self->{time_function} = $p{time_function}; |
|
56
|
12
|
|
|
|
|
28
|
|
|
57
|
12
|
|
|
|
|
30
|
# cache of last timestamp used |
|
58
|
|
|
|
|
|
|
$self->{_stamp} = ''; |
|
59
|
|
|
|
|
|
|
$self->{_time} = 0; |
|
60
|
12
|
|
|
|
|
41
|
|
|
61
|
12
|
|
|
|
|
25
|
# split pathname into basename, path, extension |
|
62
|
|
|
|
|
|
|
@$self{qw(_name _path _ext)} = fileparse($self->{filename}, '\.[^.]+'); |
|
63
|
|
|
|
|
|
|
|
|
64
|
12
|
|
|
|
|
595
|
# stored in $self->{filename} (overwrites original); used by _open_file() |
|
65
|
|
|
|
|
|
|
$self->_make_filename; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
12
|
|
|
|
|
57
|
|
|
68
|
|
|
|
|
|
|
{ |
|
69
|
|
|
|
|
|
|
my $self = shift; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# re-use last filename if the time has not changed |
|
72
|
24
|
|
|
24
|
|
45
|
my $time = time(); |
|
73
|
|
|
|
|
|
|
return $self->{filename} if $time eq $self->{_time}; |
|
74
|
|
|
|
|
|
|
|
|
75
|
24
|
|
|
|
|
54
|
$self->{_time} = $time; |
|
76
|
24
|
100
|
|
|
|
107
|
my $stamp = strftime($self->{stamp_fmt}, $self->{time_function} eq 'localtime' ? localtime : gmtime); |
|
77
|
|
|
|
|
|
|
|
|
78
|
18
|
|
|
|
|
42
|
# re-use last filename if the stamp has not changed |
|
79
|
18
|
100
|
|
|
|
828
|
return $self->{filename} if $stamp eq $self->{_stamp}; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->{filename} = catfile( |
|
82
|
18
|
50
|
|
|
|
654
|
$self->{_path}, |
|
83
|
|
|
|
|
|
|
join($self->{stamp_sep}, $self->{_name}, $stamp) . ($self->{_ext} ? $self->{_ext} : '') |
|
84
|
|
|
|
|
|
|
); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
18
|
50
|
|
|
|
760
|
|
|
87
|
|
|
|
|
|
|
{ |
|
88
|
|
|
|
|
|
|
my $self = shift; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# check if the filename is the same as last time... |
|
91
|
|
|
|
|
|
|
my $old_filename = $self->{filename}; |
|
92
|
12
|
|
|
12
|
1
|
21697
|
$self->_make_filename; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# don't re-open if we use close-after-write - the superclass will do it |
|
95
|
12
|
|
|
|
|
27
|
if (not $self->{ Log::Dispatch->VERSION >= '2.59' ? 'close_after_write' : 'close' } |
|
96
|
12
|
|
|
|
|
32
|
and $old_filename ne $self->{filename}) |
|
97
|
|
|
|
|
|
|
{ |
|
98
|
|
|
|
|
|
|
$self->_open_file; |
|
99
|
12
|
50
|
100
|
|
|
223
|
} |
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$self->SUPER::log_message(@_); |
|
102
|
1
|
|
|
|
|
4
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
|
105
|
12
|
|
|
|
|
168
|
|
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=pod |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=encoding UTF-8 |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 NAME |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Log::Dispatch::File::Stamped - Logging to date/time stamped files |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 VERSION |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
version 0.21 |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
use Log::Dispatch::File::Stamped; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $file = Log::Dispatch::File::Stamped->new( |
|
124
|
|
|
|
|
|
|
name => 'file1', |
|
125
|
|
|
|
|
|
|
min_level => 'info', |
|
126
|
|
|
|
|
|
|
filename => 'Somefile.log', |
|
127
|
|
|
|
|
|
|
stamp_fmt => '%Y%m%d', |
|
128
|
|
|
|
|
|
|
stamp_sep => ':', |
|
129
|
|
|
|
|
|
|
time_function => 'localtime', |
|
130
|
|
|
|
|
|
|
mode => 'append', |
|
131
|
|
|
|
|
|
|
); |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$file->log( level => 'emerg', message => "I've fallen and I can't get up\n" ); |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This module subclasses L<Log::Dispatch::File> for logging to date/time-stamped |
|
138
|
|
|
|
|
|
|
files, respecting all its configuration options. As with other L<Log::Dispatch> |
|
139
|
|
|
|
|
|
|
handlers, the destination file is kept open for as long as the filename remains |
|
140
|
|
|
|
|
|
|
constant (unless C<close_after_write> is set). |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 METHODS |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 new(%p) |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This method takes the same set of parameters as L<Log::Dispatch::File::new()|Log::Dispatch::File/new>, |
|
147
|
|
|
|
|
|
|
with the following differences: |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 4 |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * filename ($) |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
The filename template. The actual timestamp will be appended to this filename |
|
154
|
|
|
|
|
|
|
when creating the actual logfile. If the filename has an extension, the |
|
155
|
|
|
|
|
|
|
timestamp is inserted before the extension. See examples below. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * stamp_fmt ($) |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
The format of the timestamp string. This module uses L<POSIX::strftime|POSIX/strftime> to |
|
160
|
|
|
|
|
|
|
create the timestamp string from the current local date and time. |
|
161
|
|
|
|
|
|
|
Refer to your platform's C<strftime> documentation for the list of allowed |
|
162
|
|
|
|
|
|
|
tokens. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Defaults to C<%Y%m%d>. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * stamp_sep ($) |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
The separator character(s) used between components in the log filename. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Defaults to C<->. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * time_function ($) |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
The function used to determine the current time; present choices are L<perlfunc/localtime> or |
|
175
|
|
|
|
|
|
|
L<perlfunc/gmtime>. Defaults to C<localtime>. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=back |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 log_message( message => $ ) |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Sends a message to the appropriate output. Generally this |
|
182
|
|
|
|
|
|
|
shouldn't be called directly but should be called through the |
|
183
|
|
|
|
|
|
|
C<log()> method (in L<Log::Dispatch::Output>). |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 EXAMPLES |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=for stopwords txt |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Assuming the current date and time is: |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
% perl -e 'print scalar localtime' |
|
192
|
|
|
|
|
|
|
Sat Feb 8 13:56:13 2003 |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Log::Dispatch::File::Stamped->new( |
|
195
|
|
|
|
|
|
|
name => 'file', |
|
196
|
|
|
|
|
|
|
min_level => 'debug', |
|
197
|
|
|
|
|
|
|
filename => 'logfile.txt', |
|
198
|
|
|
|
|
|
|
); |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This will log to file F<logfile-20030208.txt>. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Log::Dispatch::File::Stamped->new( |
|
203
|
|
|
|
|
|
|
name => 'file', |
|
204
|
|
|
|
|
|
|
min_level => 'debug', |
|
205
|
|
|
|
|
|
|
filename => 'logfile.txt', |
|
206
|
|
|
|
|
|
|
stamp_fmt => '%d%H', |
|
207
|
|
|
|
|
|
|
); |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This will log to file F<logfile-0813.txt>. |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=over 4 |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item * |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
L<Log::Dispatch::File> |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item * |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
L<POSIX> |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item * |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
L<Log::Dispatch::File::Rolling> |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item * |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
L<Log::Dispatch::FileRotate> |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item * |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
L<Log::Dispatch::FileWriteRotate> |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=back |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=for stopwords Rolsky |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Dave Rolsky, author of the L<Log::Dispatch> suite and many other |
|
242
|
|
|
|
|
|
|
fine modules on CPAN. |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This module was rewritten to respect all present (and future) options to |
|
245
|
|
|
|
|
|
|
L<Log::Dispatch::File> by Karen Etheridge, <ether@cpan.org>. |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head1 SUPPORT |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Log-Dispatch-File-Stamped> |
|
250
|
|
|
|
|
|
|
(or L<bug-Log-Dispatch-File-Stamped@rt.cpan.org|mailto:bug-Log-Dispatch-File-Stamped@rt.cpan.org>). |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head1 AUTHORS |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=over 4 |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item * |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Eric Cholet <cholet@logilune.com> |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=item * |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=back |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head1 CONTRIBUTOR |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=for stopwords Sven Willenbuecher |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
Sven Willenbuecher <sven.willenbuecher@kuehne-nagel.com> |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
This software is copyright (c) 2003 by Eric Cholet and Karen Etheridge. |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
277
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=cut |