| 1 | #ABSTRACT: Logging role | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HiD::Role::DoesLogging; | ||||||||||||||||||||||||||||
| 4 | 20 | our $AUTHORITY = 'cpan:GENEHACK'; | |||||||||||||||||||||||||||
| 5 | 20 | $HiD::Role::DoesLogging::VERSION = '1.96'; | |||||||||||||||||||||||||||
| 6 | 20 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use 5.014; # strict, unicode_strings | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 20 | ▶ | use Log::Log4perl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 20 | requires 'get_config'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | has logger_config => ( | ||||||||||||||||||||||||||||
| 16 | is => 'ro' , | ||||||||||||||||||||||||||||
| 17 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 18 | lazy => 1 , | ||||||||||||||||||||||||||||
| 19 | default => sub { | ||||||||||||||||||||||||||||
| 20 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 21 | 17 | my $config = $self->get_config('logger_config'); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 17 | ▶ | return $config | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$config and %$config
MC/DC50%1/2
$config and %$config
$config
%$config
Truth table66%2/3
A and B
A= $configB= %$config
| |||||||||||||||||||||||||||||
| 24 | if ( $config && %$config ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | return { | ||||||||||||||||||||||||||||
| 27 | 3 | 'log4perl.logger' => 'WARN, Screen' , | |||||||||||||||||||||||||||
| 28 | 'log4perl.appender.Screen' => 'Log::Log4perl::Appender::Screen', | ||||||||||||||||||||||||||||
| 29 | 'log4perl.appender.Screen.layout' => 'PatternLayout' , | ||||||||||||||||||||||||||||
| 30 | 'log4perl.appender.Screen.layout.ConversionPattern' => '[%d] %5p %m%n' , | ||||||||||||||||||||||||||||
| 31 | }; | ||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||
| 33 | 20 | ); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 20 | has logger => ( | |||||||||||||||||||||||||||
| 37 | is => 'ro' , | ||||||||||||||||||||||||||||
| 38 | isa => 'Log::Log4perl::Logger', | ||||||||||||||||||||||||||||
| 39 | lazy => 1 , | ||||||||||||||||||||||||||||
| 40 | builder => '_build_logger' , | ||||||||||||||||||||||||||||
| 41 | handles => { | ||||||||||||||||||||||||||||
| 42 | DEBUG => 'debug' , | ||||||||||||||||||||||||||||
| 43 | WARN => 'warn' , | ||||||||||||||||||||||||||||
| 44 | INFO => 'info' , | ||||||||||||||||||||||||||||
| 45 | ERROR => 'error' , | ||||||||||||||||||||||||||||
| 46 | FATAL => 'fatal' , | ||||||||||||||||||||||||||||
| 47 | LOGWARN => 'logwarn' , | ||||||||||||||||||||||||||||
| 48 | }, | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub _build_logger { | ||||||||||||||||||||||||||||
| 52 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_logger: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 17 | Log::Log4perl->init( $self->logger_config ); | |||||||||||||||||||||||||||
| 55 | 17 | Log::Log4perl->get_logger(); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 20 | ▶ | no Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 20 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =pod | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head1 NAME | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | HiD::Role::DoesLogging - Logging role | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head2 logger_config | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Configuration for logging. Defaults to: | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | log4perl.logger = DEBUG, Screen | ||||||||||||||||||||||||||||
| 78 | log4perl.appender.Screen = Log::Log4perl::Appender::Screen | ||||||||||||||||||||||||||||
| 79 | log4perl.appender.Screen.layout = PatternLayout | ||||||||||||||||||||||||||||
| 80 | log4perl.appender.Screen.layout.ConversionPattern = [%d] %5p %m%n | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head2 logger | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Log4perl object for logging. Handles: | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =over | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =item * DEBUG | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =item * WARN | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =item * INFO | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =item * ERROR | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =item * FATAL | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =back | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 VERSION | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | version 1.96 | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | John SJ Anderson <genehack@genehack.org> | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | This software is copyright (c) 2015 by John SJ Anderson. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 113 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||