File Coverage

blib/lib/MooseX/Log/Log4perl/Easy.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 6 6 100.0
total 28 28 100.0


line stmt bran cond sub pod time code
1             package MooseX::Log::Log4perl::Easy;
2              
3 2     2   7774 use Moo::Role;
  2         2  
  2         9  
4              
5             with 'MooseX::Log::Log4perl';
6              
7             our $VERSION = '0.47';
8              
9 1     1 1 118 sub log_fatal { local $Log::Log4perl::caller_depth += 1; return shift->logger->fatal(@_); }
  1         17  
10 1     1 1 117 sub log_error { local $Log::Log4perl::caller_depth += 1; return shift->logger->error(@_); }
  1         23  
11 1     1 1 119 sub log_warn { local $Log::Log4perl::caller_depth += 1; return shift->logger->warn(@_); }
  1         17  
12 1     1 1 125 sub log_info { local $Log::Log4perl::caller_depth += 1; return shift->logger->info(@_); }
  1         17  
13 1     1 1 402 sub log_debug { local $Log::Log4perl::caller_depth += 1; return shift->logger->debug(@_); }
  1         19  
14 1     1 1 7867 sub log_trace { local $Log::Log4perl::caller_depth += 1; return shift->logger->trace(@_); }
  1         21  
15              
16             1;
17              
18             __END__
19              
20             =head1 NAME
21              
22             MooseX::Log::Log4perl::Easy - A role for easy usage of logging in your Moose based modules based on L<MooseX::Log::Log4perl>
23              
24             =head1 SYNOPSIS
25              
26             package MyApp;
27             use Moose;
28             use Log::Log4perl qw(:easy);
29              
30             with 'MooseX::Log::Log4perl::Easy';
31              
32             BEGIN {
33             Log::Log4perl->easy_init();
34             }
35              
36             sub foo {
37             my ($self) = @_;
38             $self->log_debug("started bar"); ### logs with default class catergory "MyApp"
39             $self->log_info('bar'); ### logs an info message
40             $self->log('AlsoPossible')->fatal("croak"); ### log
41             }
42              
43             =head1 DESCRIPTION
44              
45             The "Easy" logging role based on the L<MooseX::Log::Log4perl> logging role for
46             Moose directly adds the log methods for all available levels to your class
47             instance. Hence it is possible to use
48              
49             $self->log_info("blabla");
50              
51             without having to access a separate log attribute as in MooseX::Log::Log4perl;
52              
53             In case your app grows and you need more of the super-cow powers of Log4perl or
54             simply don't want the additional methods to clutter up your class you can simply
55             replace all code C<< $self->log_LEVEL >> with C<< $self->log->LEVEL >>.
56              
57             You can use the following regex substitution to accomplish that:
58              
59             s/log(_(trace|debug|info|warn|error|fatal))/log->$2/g
60              
61             =head1 ACCESSORS
62              
63             =head2 logger
64              
65             See L<MooseX::Log::Log4perl>
66              
67             =head2 log
68              
69             See L<MooseX::Log::Log4perl>
70              
71             =head2 log_fatal ($msg)
72              
73             Logs a fatal message $msg using the logger attribute. Same as calling
74              
75             $self->logger->fatal($msg)
76              
77             =head2 log_error ($msg)
78              
79             Logs an error message using the logger attribute. Same as calling
80              
81             $self->logger->error($msg)
82              
83             =head2 log_warn ($msg)
84              
85             Logs a warn message using the logger attribute. Same as calling
86              
87             $self->logger->warn($msg)
88              
89             =head2 log_info ($msg)
90              
91             Logs an info message using the logger attribute. Same as calling
92              
93             $self->logger->info($msg)
94              
95             =head2 log_debug ($msg)
96              
97             Logs a debug message using the logger attribute. Same as calling
98              
99             $self->logger->debug($msg)
100              
101             =head2 log_trace ($msg)
102              
103             Logs a trace message using the logger attribute. Same as calling
104              
105             $self->logger->trace($msg)
106              
107             =head1 SEE ALSO
108              
109             L<MooseX::Log::Log4perl>
110              
111             =head1 AUTHOR
112              
113             Roland Lammel C<< <lammel@cpan.org> >>
114              
115             =head1 LICENSE AND COPYRIGHT
116              
117             Copyright (c) 2008-2016, Roland Lammel L<< <lammel@cpan.org> >>, http://www.quikit.at
118              
119             This module is free software; you can redistribute it and/or
120             modify it under the same terms as Perl itself. See L<perlartistic>.