line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Clustericious::Log; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
904
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
75
|
|
4
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
94
|
|
5
|
2
|
|
|
2
|
|
21
|
use List::Util qw( first ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
291
|
|
6
|
2
|
|
|
2
|
|
3093
|
use Log::Log4perl qw( :easy ); |
|
2
|
|
|
|
|
125913
|
|
|
2
|
|
|
|
|
15
|
|
7
|
2
|
|
|
2
|
|
3231
|
use MojoX::Log::Log4perl; |
|
2
|
|
|
|
|
23134
|
|
|
2
|
|
|
|
|
30
|
|
8
|
2
|
|
|
2
|
|
1999
|
use File::ReadBackwards; |
|
2
|
|
|
|
|
2498
|
|
|
2
|
|
|
|
|
60
|
|
9
|
2
|
|
|
2
|
|
1021
|
use File::HomeDir; |
|
2
|
|
|
|
|
5652
|
|
|
2
|
|
|
|
|
234
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: A Log::Log4perl wrapper for use with Clustericious. |
12
|
|
|
|
|
|
|
our $VERSION = '0.15'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub import { |
16
|
2
|
|
|
2
|
|
25
|
my $class = shift; |
17
|
2
|
|
|
|
|
5
|
my $dest = caller; |
18
|
2
|
|
|
|
|
7
|
my %args = @_; |
19
|
2
|
100
|
|
|
|
13
|
if (my $app_name = $args{-init_logging}) { |
20
|
1
|
|
|
|
|
3
|
init_logging($app_name); |
21
|
|
|
|
|
|
|
} |
22
|
2
|
|
|
2
|
|
10
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1485
|
|
23
|
2
|
|
|
|
|
8
|
*{"${dest}::$_"} = *{"${class}::$_"} for qw/TRACE INFO DEBUG ERROR WARN FATAL LOGDIE get_logger/; |
|
16
|
|
|
|
|
119
|
|
|
16
|
|
|
|
|
47
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $initPid; |
28
|
|
|
|
|
|
|
sub init_logging { |
29
|
1
|
|
|
1
|
1
|
2
|
my $app_name = shift; |
30
|
1
|
50
|
|
|
|
2
|
$app_name = shift if $app_name eq __PACKAGE__; |
31
|
1
|
50
|
33
|
|
|
8
|
$app_name = $ENV{MOJO_APP} unless $app_name && $app_name ne 'Clustericious::App'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Force reinitialization after a fork |
34
|
1
|
50
|
33
|
|
|
3
|
$Log::Log4perl::Logger::INITIALIZED = 0 if $initPid && $initPid != $$; |
35
|
1
|
|
|
|
|
4
|
$initPid = $$; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
6
|
my $home = File::HomeDir->my_home; |
38
|
1
|
|
|
|
|
26
|
my @Confdirs = ($home, "$home/etc", "/util/etc", "/etc" ); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Logging |
41
|
1
|
|
50
|
|
|
10
|
$ENV{LOG_LEVEL} ||= 'WARN'; |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
2
|
my $l4p_dir; # dir with log config file. |
44
|
|
|
|
|
|
|
my $l4p_pat; # pattern for screen logging |
45
|
0
|
|
|
|
|
0
|
my $l4p_file; # file (global or app specific) |
46
|
|
|
|
|
|
|
|
47
|
1
|
50
|
66
|
2
|
|
12
|
$l4p_dir = first { -d $_ && (-e "$_/log4perl.conf" || -e "$_/$app_name.log4perl.conf") } @Confdirs; |
|
2
|
|
|
|
|
97
|
|
48
|
1
|
|
|
|
|
4
|
$l4p_pat = "[%d] [%Z %H %P] %5p: %m%n"; |
49
|
1
|
50
|
|
|
|
3
|
if ($l4p_dir) { |
50
|
1
|
|
|
2
|
|
1116
|
$l4p_file = first {-e "$l4p_dir/$_"} ("$app_name.log4perl.conf", "log4perl.conf"); |
|
2
|
|
|
|
|
39
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
0
|
|
10
|
Log::Log4perl::Layout::PatternLayout::add_global_cspec('Z', sub {$app_name}); |
|
0
|
|
|
|
|
0
|
|
54
|
|
|
|
|
|
|
|
55
|
1
|
0
|
|
|
|
39
|
my $logger = MojoX::Log::Log4perl->new( $l4p_dir ? "$l4p_dir/$l4p_file": |
|
|
50
|
|
|
|
|
|
56
|
|
|
|
|
|
|
{ # default config |
57
|
|
|
|
|
|
|
($ENV{LOG_FILE} ? ( |
58
|
|
|
|
|
|
|
"log4perl.rootLogger" => "$ENV{LOG_LEVEL}, File1", |
59
|
|
|
|
|
|
|
"log4perl.appender.File1" => "Log::Log4perl::Appender::File", |
60
|
|
|
|
|
|
|
"log4perl.appender.File1.layout" => "PatternLayout", |
61
|
|
|
|
|
|
|
"log4perl.appender.File1.filename" => "$ENV{LOG_FILE}", |
62
|
|
|
|
|
|
|
"log4perl.appender.File1.layout.ConversionPattern" => "[%d] [%Z %H %P] %5p: %m%n", |
63
|
|
|
|
|
|
|
):( |
64
|
|
|
|
|
|
|
"log4perl.rootLogger" => "$ENV{LOG_LEVEL}, SCREEN", |
65
|
|
|
|
|
|
|
"log4perl.appender.SCREEN" => "Log::Log4perl::Appender::Screen", |
66
|
|
|
|
|
|
|
"log4perl.appender.SCREEN.layout" => "PatternLayout", |
67
|
|
|
|
|
|
|
"log4perl.appender.SCREEN.layout.ConversionPattern" => "$l4p_pat", |
68
|
|
|
|
|
|
|
)), |
69
|
|
|
|
|
|
|
# These categories (%c) are too verbose by default : |
70
|
|
|
|
|
|
|
"log4perl.logger.Mojolicious" => "WARN", |
71
|
|
|
|
|
|
|
"log4perl.logger.Mojolicious.Plugin.RequestTimer" => "WARN", |
72
|
|
|
|
|
|
|
"log4perl.logger.MojoX.Dispatcher.Routes" => "WARN", |
73
|
|
|
|
|
|
|
}); |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
15410
|
INFO("Initialized logger"); |
76
|
1
|
50
|
|
|
|
1149
|
INFO("Log config found : $l4p_dir/$l4p_file") if $l4p_dir; |
77
|
|
|
|
|
|
|
# warn "# started logging ($l4p_dir/log4perl.conf)\n" if $l4p_dir; |
78
|
1
|
|
|
|
|
642
|
return $logger; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub tail { |
83
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
84
|
0
|
|
|
|
|
|
my %args = @_; |
85
|
0
|
|
0
|
|
|
|
my $count = $args{lines} || 10; |
86
|
0
|
|
|
|
|
|
my %appenders = %{ Log::Log4perl->appenders }; |
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my ($first) = sort keys %appenders; |
88
|
0
|
|
|
|
|
|
my $obj = $appenders{$first}->{appender}; |
89
|
0
|
0
|
|
|
|
|
$obj->can("filename") or return "no filename for appender $first"; |
90
|
0
|
|
|
|
|
|
my $filename = $obj->filename; |
91
|
0
|
0
|
|
|
|
|
my $fp = File::ReadBackwards->new($filename) or return "Can't read $filename : $!"; |
92
|
0
|
|
|
|
|
|
my @lines; |
93
|
|
|
|
|
|
|
my $line; |
94
|
0
|
|
|
|
|
|
while ( defined( $line = $fp->readline ) ) { |
95
|
0
|
|
|
|
|
|
unshift @lines, $line; |
96
|
0
|
0
|
|
|
|
|
last if ( (0 + @lines) >= $count); |
97
|
|
|
|
|
|
|
}; |
98
|
0
|
|
|
|
|
|
return join '', @lines; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |