| 1 | package MooseX::App::Role::Log4perl; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use 5.010_000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use MooseX::App::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Log::Log4perl qw(:easy); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | our $VERSION = "0.03"; | |||||||||
| 11 | |||||||||||
| 12 | 1 | 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 | 1 | option 'debug' => | |||||||||
| 22 | ( | ||||||||||
| 23 | is => 'rw', | ||||||||||
| 24 | isa => 'Bool', | ||||||||||
| 25 | documentation => q[Turn on debug mode], | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 1 | option 'quiet' => | |||||||||
| 29 | ( | ||||||||||
| 30 | is => 'ro', | ||||||||||
| 31 | isa => 'Bool', | ||||||||||
| 32 | documentation => q[Turn off log messages written to STDOUT], | ||||||||||
| 33 | ); | ||||||||||
| 34 | |||||||||||
| 35 | 1 | has 'log' => ( | |||||||||
| 36 | is => 'rw', | ||||||||||
| 37 | lazy => 1, | ||||||||||
| 38 | builder => '_init_logging', | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | sub _init_logging | ||||||||||
| 42 | 0 | ▶ | { | ||||||||
|
Subroutine
_init_logging: not called CC=4 SCAR=30.0
| |||||||||||
| 43 | 0 | my $self = shift; | |||||||||
| 44 | |||||||||||
| 45 | # Setup logging. | ||||||||||
| 46 | 0 | ▶ | my $log_level = $self->debug ? "DEBUG" : "INFO"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | my $log_cat = "$log_level, Screen"; | |||||||||
| 48 | 0 | ▶ | $log_cat .= ", Logfile" if $self->logfile; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | ▶ | my $screen_threshold = $self->quiet ? "OFF" : $log_level; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | my $file_path = $self->logfile; | |||||||||
| 51 | 0 | 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 | 0 | Log::Log4perl::init( \$log_conf ); | |||||||||
| 64 | 0 | return Log::Log4perl::get_logger(); | |||||||||
| 65 | |||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 1 | 1; | |||||||||
| 69 | __END__ | ||||||||||