line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::File::RotateLogs; |
2
|
2
|
|
|
2
|
|
3853
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
96
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
76
|
|
4
|
2
|
|
|
2
|
|
814
|
use MRO::Compat; |
|
2
|
|
|
|
|
4200
|
|
|
2
|
|
|
|
|
381
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.05"; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub setup { |
8
|
1
|
|
|
1
|
0
|
175107
|
my $c = shift; |
9
|
1
|
|
|
|
|
8
|
my $home = $c->config->{home}; |
10
|
1
|
|
50
|
|
|
91
|
my $config = $c->config->{'File::RotateLogs'} || { |
11
|
|
|
|
|
|
|
logfile => "${home}/root/error_log.%Y%m%d%H", |
12
|
|
|
|
|
|
|
linkname => "${home}/root/error_log", |
13
|
|
|
|
|
|
|
rotationtime => 86400, #default 1day |
14
|
|
|
|
|
|
|
maxage => 86400 * 3, #3day |
15
|
|
|
|
|
|
|
autodump => 0, |
16
|
|
|
|
|
|
|
}; |
17
|
1
|
|
|
|
|
102
|
$config->{maxage} = int eval($config->{maxage}); |
18
|
1
|
|
|
|
|
8
|
$c->log((__PACKAGE__ . '::Backend')->new($config)); |
19
|
1
|
|
|
|
|
66
|
return $c->maybe::next::method(@_); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package Catalyst::Plugin::File::RotateLogs::Backend; |
23
|
2
|
|
|
2
|
|
902
|
use Moose; |
|
2
|
|
|
|
|
514390
|
|
|
2
|
|
|
|
|
17
|
|
24
|
2
|
|
|
2
|
|
14462
|
use Time::Piece; |
|
2
|
|
|
|
|
25483
|
|
|
2
|
|
|
|
|
13
|
|
25
|
2
|
|
|
2
|
|
1374
|
use File::RotateLogs; |
|
2
|
|
|
|
|
69104
|
|
|
2
|
|
|
|
|
86
|
|
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
2
|
|
12
|
BEGIN { extends 'Catalyst::Log' } |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $ROTATE_LOGS; |
30
|
|
|
|
|
|
|
my $CALLER_DEPTH = 1; |
31
|
|
|
|
|
|
|
my $AUTODUMP = 0; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
1
|
|
|
1
|
1
|
2
|
my $class = shift; |
35
|
1
|
|
|
|
|
2
|
my $config = shift; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
50
|
|
|
5
|
$AUTODUMP = $config->{autodump} //= 0; |
38
|
1
|
|
|
|
|
3
|
delete $config->{autodump}; |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
7
|
my $self = $class->next::method(); |
41
|
1
|
|
|
|
|
1564
|
$ROTATE_LOGS = File::RotateLogs->new($config); |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
116
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
{ |
47
|
|
|
|
|
|
|
foreach my $handler (qw/debug info warn error fatal/) { |
48
|
|
|
|
|
|
|
override $handler => sub { |
49
|
|
|
|
|
|
|
my ($self, $message) = @_; |
50
|
|
|
|
|
|
|
if ($AUTODUMP && ref($message) ) { |
51
|
|
|
|
|
|
|
local $Data::Dumper::Terse = 1; |
52
|
|
|
|
|
|
|
local $Data::Dumper::Indent = 0; |
53
|
|
|
|
|
|
|
local $Data::Dumper::Sortkeys = 1; |
54
|
|
|
|
|
|
|
$message = Data::Dumper::Dumper($message); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
my ($package, $file, $line) = caller($CALLER_DEPTH); |
57
|
|
|
|
|
|
|
#todo: enables to change a format |
58
|
|
|
|
|
|
|
$ROTATE_LOGS->print(sprintf(qq{%s: [%s] [%s] %s at %s line %s\n}, |
59
|
|
|
|
|
|
|
localtime->datetime, uc $handler, $package, $message, $file, $line)); |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
__END__ |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=pod |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Catalyst::Plugin::File::RotateLogs - Catalyst Plugin for File::RotateLogs |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SYNOPSIS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# plugin is loaded |
77
|
|
|
|
|
|
|
use Catalyst qw/ |
78
|
|
|
|
|
|
|
ConfigLoader |
79
|
|
|
|
|
|
|
Static::Simple |
80
|
|
|
|
|
|
|
File::RotateLogs |
81
|
|
|
|
|
|
|
/; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$c->log->info("hello catalyst"); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Catalyst configuration by default (e. g. in YAML format): |
86
|
|
|
|
|
|
|
File::RotateLogs: |
87
|
|
|
|
|
|
|
logfile: '/[absolute path]/root/error.log.%Y%m%d%H' |
88
|
|
|
|
|
|
|
linkname: '/[absolute path]/root/error.log' |
89
|
|
|
|
|
|
|
rotationtime: 86400 |
90
|
|
|
|
|
|
|
maxage: 86400 * 3 |
91
|
|
|
|
|
|
|
autodump: 0 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This module allows you to initialize File::RotateLogs within the application's configuration. File::RotateLogs is utility for file logger and very simple logfile rotation. I wanted easier catalyst log rotation. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SEE ALSO |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 2 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item L<Catalyst::Log> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item L<File::RotateLogs> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=back |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 LICENSE |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
110
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
masakyst E<lt>masakyst.public@gmail.comE<gt> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |