| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MooseX::App::Role::Log4perl; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1016
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
42
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
5
|
1
|
|
|
1
|
|
43
|
use 5.010_000; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
6
|
1
|
|
|
1
|
|
549
|
use Moose::Role; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use MooseX::App::Role; |
|
8
|
|
|
|
|
|
|
use Log::Log4perl qw(:easy); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
option 'logfile' => |
|
13
|
|
|
|
|
|
|
( |
|
14
|
|
|
|
|
|
|
is => 'rw', |
|
15
|
|
|
|
|
|
|
isa => 'Str', |
|
16
|
|
|
|
|
|
|
documentation => q[Path to file used for logging ], |
|
17
|
|
|
|
|
|
|
cmd_flag => 'log', |
|
18
|
|
|
|
|
|
|
default => '', |
|
19
|
|
|
|
|
|
|
); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
option 'debug' => |
|
22
|
|
|
|
|
|
|
( |
|
23
|
|
|
|
|
|
|
is => 'rw', |
|
24
|
|
|
|
|
|
|
isa => 'Bool', |
|
25
|
|
|
|
|
|
|
documentation => q[Turn on debug mode], |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
option 'quiet' => |
|
29
|
|
|
|
|
|
|
( |
|
30
|
|
|
|
|
|
|
is => 'ro', |
|
31
|
|
|
|
|
|
|
isa => 'Bool', |
|
32
|
|
|
|
|
|
|
documentation => q[Turn off log messages written to STDOUT], |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has 'log' => ( |
|
36
|
|
|
|
|
|
|
is => 'rw', |
|
37
|
|
|
|
|
|
|
lazy => 1, |
|
38
|
|
|
|
|
|
|
builder => '_init_logging', |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _init_logging |
|
42
|
|
|
|
|
|
|
{ |
|
43
|
|
|
|
|
|
|
my $self = shift; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Setup logging. |
|
46
|
|
|
|
|
|
|
my $log_level = $self->debug ? "DEBUG" : "INFO"; |
|
47
|
|
|
|
|
|
|
my $log_cat = "$log_level, Screen"; |
|
48
|
|
|
|
|
|
|
$log_cat .= ", Logfile" if $self->logfile; |
|
49
|
|
|
|
|
|
|
my $screen_threshold = $self->quiet ? "OFF" : $log_level; |
|
50
|
|
|
|
|
|
|
my $file_path = $self->logfile; |
|
51
|
|
|
|
|
|
|
my $log_conf = qq( |
|
52
|
|
|
|
|
|
|
log4perl.category = $log_cat |
|
53
|
|
|
|
|
|
|
log4perl.appender.Screen = Log::Log4perl::Appender::Screen |
|
54
|
|
|
|
|
|
|
log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout |
|
55
|
|
|
|
|
|
|
log4perl.appender.Screen.layout.ConversionPattern = %p - %m%n |
|
56
|
|
|
|
|
|
|
log4perl.appender.Screen.Threshold = $screen_threshold |
|
57
|
|
|
|
|
|
|
log4perl.appender.Logfile = Log::Log4perl::Appender::File |
|
58
|
|
|
|
|
|
|
log4perl.appender.Logfile.filename = $file_path |
|
59
|
|
|
|
|
|
|
log4perl.appender.Logfile.mode = append |
|
60
|
|
|
|
|
|
|
log4perl.appender.Logfile.layout = Log::Log4perl::Layout::PatternLayout |
|
61
|
|
|
|
|
|
|
log4perl.appender.Logfile.layout.ConversionPattern = %d %p - %m%n |
|
62
|
|
|
|
|
|
|
); |
|
63
|
|
|
|
|
|
|
Log::Log4perl::init( \$log_conf ); |
|
64
|
|
|
|
|
|
|
return Log::Log4perl::get_logger(); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
|
69
|
|
|
|
|
|
|
__END__ |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=encoding utf-8 |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
MooseX::App::Role::Log4perl - Add basic Log::Log4perl logging to a MooseX::App application as a role. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
use MooseX::App::Simple; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
with MooseX::App::Role::Log4perl |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub run |
|
84
|
|
|
|
|
|
|
{ |
|
85
|
|
|
|
|
|
|
my $self = shift; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$self->log->debug("This is a DEBUG message"); |
|
88
|
|
|
|
|
|
|
$self->log->info("This is an INFO message"); |
|
89
|
|
|
|
|
|
|
$self->log->warn("This is a WARN message"); |
|
90
|
|
|
|
|
|
|
$self->log->error("This is an ERROR message"); |
|
91
|
|
|
|
|
|
|
$self->log->fatal("This is a FATAL message"); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
The is a role built for CLI apps using the MooseX::App framework. It adds the following command line options: |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
--logfile #write log4perl output to a file |
|
100
|
|
|
|
|
|
|
--debug #include your debug log messages |
|
101
|
|
|
|
|
|
|
--quiet #suppress output to the terminal (STDOUT) |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
By default this role will only log messages to STDOUT with INFO or higher priority. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 LICENSE |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Copyright (C) John Dexter. |
|
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
|
|
|
|
|
|
|
John Dexter |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |