line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Dispatch::CronoDir; |
2
|
2
|
|
|
2
|
|
17920
|
use 5.008001; |
|
2
|
|
|
|
|
5
|
|
3
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
32
|
|
4
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
52
|
|
5
|
2
|
|
|
2
|
|
394
|
use parent qw(Log::Dispatch::Output); |
|
2
|
|
|
|
|
238
|
|
|
2
|
|
|
|
|
9
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.05"; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
23664
|
use File::Path qw(make_path); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
101
|
|
10
|
2
|
|
|
2
|
|
10
|
use Params::Validate qw(validate SCALAR BOOLEAN); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
104
|
|
11
|
2
|
|
|
2
|
|
13
|
use Scalar::Util qw(openhandle); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1174
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Params::Validate::validation_options(allow_extra => 1); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
8
|
|
|
8
|
1
|
4854
|
my ($proto, %args) = @_; |
17
|
8
|
|
33
|
|
|
35
|
my $class = ref $proto || $proto; |
18
|
8
|
|
|
|
|
11
|
my $self = bless {}, $class; |
19
|
8
|
|
|
|
|
35
|
$self->_basic_init(%args); |
20
|
8
|
|
|
|
|
641
|
$self->_init(%args); |
21
|
6
|
|
|
|
|
17
|
$self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _init { |
25
|
8
|
|
|
8
|
|
8
|
my $self = shift; |
26
|
8
|
|
|
|
|
251
|
my %args = validate( |
27
|
|
|
|
|
|
|
@_, |
28
|
|
|
|
|
|
|
{ dirname_pattern => { type => SCALAR }, |
29
|
|
|
|
|
|
|
permissions => { |
30
|
|
|
|
|
|
|
type => SCALAR, |
31
|
|
|
|
|
|
|
default => 0755, |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
filename => { type => SCALAR }, |
34
|
|
|
|
|
|
|
mode => { |
35
|
|
|
|
|
|
|
type => SCALAR, |
36
|
|
|
|
|
|
|
default => '>>', |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
binmode => { |
39
|
|
|
|
|
|
|
type => SCALAR, |
40
|
|
|
|
|
|
|
optional => 1, |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
autoflush => { |
43
|
|
|
|
|
|
|
type => BOOLEAN, |
44
|
|
|
|
|
|
|
default => 1, |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
6
|
|
|
|
|
40
|
my @rules; |
50
|
6
|
|
|
|
|
28
|
$args{dirname_pattern} =~ s{ \% (\w) }{ |
51
|
|
|
|
|
|
|
$1 eq 'Y' ? do { |
52
|
6
|
|
|
|
|
13
|
push @rules, { pos => 5, offset => 1900 }; |
53
|
6
|
|
|
|
|
20
|
'%04d'; |
54
|
|
|
|
|
|
|
} : $1 eq 'm' ? do { |
55
|
6
|
|
|
|
|
9
|
push @rules, { pos => 4, offset => 1 }; |
56
|
6
|
|
|
|
|
12
|
'%02d'; |
57
|
18
|
50
|
|
|
|
43
|
} : $1 eq 'd' ? do { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
58
|
6
|
|
|
|
|
8
|
push @rules, { pos => 3, offset => 0 }; |
59
|
6
|
|
|
|
|
10
|
'%02d'; |
60
|
|
|
|
|
|
|
} : ''; |
61
|
|
|
|
|
|
|
}egx; |
62
|
|
|
|
|
|
|
|
63
|
6
|
|
|
|
|
10
|
$self->{_rules} = \@rules; |
64
|
6
|
|
|
|
|
9
|
$self->{_dirname_pattern} = $args{dirname_pattern}; |
65
|
6
|
|
|
|
|
7
|
$self->{_permissions} = $args{permissions}; |
66
|
6
|
|
|
|
|
7
|
$self->{_filename} = $args{filename}; |
67
|
6
|
|
|
|
|
6
|
$self->{_mode} = $args{mode}; |
68
|
6
|
|
|
|
|
6
|
$self->{_binmode} = $args{binmode}; |
69
|
6
|
|
|
|
|
5
|
$self->{_autoflush} = $args{autoflush}; |
70
|
|
|
|
|
|
|
|
71
|
6
|
|
|
|
|
10
|
$self->_get_current_fh; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
3
|
|
|
3
|
|
127
|
sub _localtime { localtime } |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _find_current_dir { |
77
|
10
|
|
|
10
|
|
7
|
my $self = shift; |
78
|
10
|
|
|
|
|
17
|
my @now = _localtime(); |
79
|
|
|
|
|
|
|
sprintf( |
80
|
|
|
|
|
|
|
$self->{_dirname_pattern}, |
81
|
10
|
|
|
|
|
46
|
map { $now[ $_->{pos} ] + $_->{offset} } @{ $self->{_rules} }, |
|
30
|
|
|
|
|
73
|
|
|
10
|
|
|
|
|
15
|
|
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _get_current_fh { |
86
|
10
|
|
|
10
|
|
8
|
my $self = shift; |
87
|
10
|
|
|
|
|
18
|
my $dirname = $self->_find_current_dir; |
88
|
|
|
|
|
|
|
|
89
|
10
|
100
|
100
|
|
|
50
|
if (!exists $self->{_current_dir} || $dirname ne $self->{_current_dir}) { |
90
|
|
|
|
|
|
|
close $self->{_current_fh} |
91
|
7
|
100
|
66
|
|
|
25
|
if $self->{_current_fh} and openhandle($self->{_current_fh}); |
92
|
|
|
|
|
|
|
|
93
|
7
|
|
|
|
|
1694
|
make_path $dirname; |
94
|
7
|
|
|
|
|
14
|
$self->{_current_dir} = $dirname; |
95
|
7
|
|
|
|
|
68
|
$self->{_current_filepath} = File::Spec->catfile($dirname, $self->{_filename}); |
96
|
|
|
|
|
|
|
|
97
|
7
|
50
|
|
|
|
108
|
chmod $self->{_permissions}, $dirname |
98
|
|
|
|
|
|
|
or die "Failed chmod $dirname to $self->{_permissions}: $!"; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
open my $fh, $self->{_mode}, $self->{_current_filepath} |
101
|
7
|
50
|
|
|
|
348
|
or die "Failed opening file $self->{current_filepath} to write: $!"; |
102
|
|
|
|
|
|
|
|
103
|
7
|
100
|
|
|
|
19
|
binmode $fh, $self->{_binmode} if $self->{_binmode}; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
do { |
106
|
7
|
|
|
|
|
16
|
my $oldfh = select $fh; |
107
|
7
|
|
|
|
|
14
|
$| = 1; |
108
|
7
|
|
|
|
|
25
|
select $oldfh; |
109
|
7
|
50
|
|
|
|
12
|
} if $self->{_autoflush}; |
110
|
|
|
|
|
|
|
|
111
|
7
|
|
|
|
|
83
|
$self->{_current_fh} = $fh; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
10
|
|
|
|
|
169
|
$self->{_current_fh}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub log_message { |
118
|
4
|
|
|
4
|
0
|
1980
|
my ($self, %args) = @_; |
119
|
4
|
|
|
|
|
6
|
print { $self->_get_current_fh } $args{message} |
120
|
4
|
50
|
|
|
|
5
|
or die "Cannot write to file $self->{_current_file}: $!"; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub DESTROY { |
124
|
8
|
|
|
8
|
|
5585
|
my $self = shift; |
125
|
|
|
|
|
|
|
close $self->{_current_fh} |
126
|
8
|
100
|
66
|
|
|
136
|
if $self->{_current_fh} and openhandle($self->{_current_fh}); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
__END__ |