line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::Logger::File::RotateLogs; |
2
|
|
|
|
|
|
|
$Dancer2::Logger::File::RotateLogs::VERSION = '0.01'; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
988
|
use Moo; |
|
1
|
|
|
|
|
10110
|
|
|
1
|
|
|
|
|
4
|
|
5
|
1
|
|
|
1
|
|
1103
|
use File::Spec; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
6
|
1
|
|
|
1
|
|
430
|
use File::RotateLogs; |
|
1
|
|
|
|
|
30982
|
|
|
1
|
|
|
|
|
32
|
|
7
|
1
|
|
|
1
|
|
539
|
use Dancer2::Core::Types; |
|
1
|
|
|
|
|
6517
|
|
|
1
|
|
|
|
|
700
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'Dancer2::Core::Role::Logger'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $ROTATELOGS; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has environment => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
required => 1, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has location => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
required => 1, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has log_dir => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => sub { |
26
|
|
|
|
|
|
|
my $dir = shift; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
if ( !-d $dir && !mkdir $dir ) { |
29
|
|
|
|
|
|
|
die "log directory \"$dir\" does not exist and unable to create it."; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
if ( !-w $dir ) { |
32
|
|
|
|
|
|
|
die "log directory \"$dir\" is not writable." |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
lazy => 1, |
36
|
|
|
|
|
|
|
builder => '_build_log_dir', |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has logfile => ( |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
required => 1, |
42
|
|
|
|
|
|
|
lazy => 1, |
43
|
|
|
|
|
|
|
default => sub { |
44
|
|
|
|
|
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
File::Spec->catfile(File::Spec->rel2abs($self->log_dir), $self->environment.'.log').".%Y%m%d%H"; |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has linkname => ( |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
required => 1, |
52
|
|
|
|
|
|
|
lazy => 1, |
53
|
|
|
|
|
|
|
default => sub { |
54
|
|
|
|
|
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
File::Spec->catfile(File::Spec->rel2abs($self->log_dir), $self->environment.'.log'); |
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
has rotationtime => ( |
60
|
|
|
|
|
|
|
is => 'ro', |
61
|
|
|
|
|
|
|
required => 1, |
62
|
|
|
|
|
|
|
default => sub { 86400 }, |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
has maxage => ( |
66
|
|
|
|
|
|
|
is => 'ro', |
67
|
|
|
|
|
|
|
required => 1, |
68
|
|
|
|
|
|
|
default => sub { 86400 * 7 }, |
69
|
|
|
|
|
|
|
coerce => sub { |
70
|
|
|
|
|
|
|
$_[0] =~ /^\d+$/ ? $_[0] : int eval($_[0]) |
71
|
|
|
|
|
|
|
}, |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub BUILD { |
75
|
|
|
|
|
|
|
my ($self) = @_; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$ROTATELOGS = File::RotateLogs->new({ |
78
|
|
|
|
|
|
|
logfile => $self->logfile, |
79
|
|
|
|
|
|
|
linkname => $self->linkname, |
80
|
|
|
|
|
|
|
rotationtime => $self->rotationtime, |
81
|
|
|
|
|
|
|
maxage => $self->maxage, |
82
|
|
|
|
|
|
|
}); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _build_log_dir { |
86
|
0
|
|
|
0
|
|
|
File::Spec->catdir( $_[0]->location, 'logs' ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub log { |
90
|
0
|
|
|
0
|
0
|
|
my ( $self, $level, $message ) = @_; |
91
|
0
|
|
|
|
|
|
$ROTATELOGS->print($self->format_message( $level => $message )); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
__END__ |