blib/lib/Prancer/Plugin/Log4perl.pm

filter: Statementstmt 82.8% 29 / 35 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 2 totaltotal 75.5% 37 / 49 CC 2 SCAR 6.9
CC
2
Cov
78%
load
6.0
logger
2.0
BEGIN
1.0
CRAP 2.0
↑ Summary
1 package Prancer::Plugin::Log4perl;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our $VERSION = '1.01';
8  
9 1 ▶use Prancer::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use parent qw(Prancer::Plugin Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Log::Log4perl ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our @EXPORT_OK = qw(logger);
17 1 our %EXPORT_TAGS = ('all' => [ @EXPORT_OK ]);
18  
19 # even though this *should* work automatically, it was not
20 1 our @CARP_NOT = qw(Prancer Try::Tiny);
21  
22 0 ▶sub load {
Subroutine load: not called CC=2 SCAR=17.9
Pod undocumented
23 0 my $class = shift;
24  
25 # initialize the logger if necessary
26 0 ▶ if (!Log::Log4perl->initialized()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Log::Log4perl"->initialized) 0 0 0
27 0 Log::Log4perl->init(\qq|
28 log4perl.rootLogger = INFO, stdout
29 log4perl.appender.stdout = Log::Dispatch::Screen
30 log4perl.appender.stdout.stderr = 0
31 log4perl.appender.stdout.layout = Log::Log4perl::Layout::PatternLayout
32 log4perl.appender.stdout.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss,SSS} %5p [%c{1}:%M:%L] - %m%n
33 |);
34 }
35  
36 0 return bless({}, $class);
37 }
38  
39 0 ▶sub logger {
Subroutine logger: not called CC=1 SCAR=6.9
Pod undocumented
40 0 my $package = (caller())[0];
41 0 return Log::Log4perl->get_logger($package);
42 }
43  
44 1 1;
45  
46 =head1 NAME
47  
48 Prancer::Plugin::Log4perl
49  
50 =head1 SYNOPSIS
51  
52 This plugin connects your L<Prancer> application to L<Log::Log4perl> and
53 exports a keyword to access the configured logger. You don't I<need> this
54 module to log things but it certainly makes it easier.
55  
56 There is very minimal configuration required to get started with this module.
57 To enable the logger you only need to do this:
58  
59 use Prancer::Plugin::Log4perl qw(logger);
60  
61 Prancer::Plugin::Log4perl->load();
62  
63 logger->info("hello, logger here");
64 logger->fatal("something done broke");
65  
66 By default, this plugin will initialize L<Log::Log4perl> with a very basic
67 configuration to avoid warnings when used. You can override the configuration
68 by loading your own before calling C<load> on this plugin. This plugin's
69 C<load> implementation simply calls C<Log::Log4perl-E<gt>initialized()> to see
70 if it should load its own. For example, you might do this:
71  
72 use Prancer::Plugin::Log4perl qw(logger);
73  
74 Log::Log4perl::init('/etc/log4perl.conf');
75 Prancer::Plugin::Log4perl->load();
76  
77 The C<logger> keyword gets you direct access to an instance of the logger and
78 you can always call static methods on L<Log::Log4perl> and interact with the
79 logger that way, too.
80  
81 =head1 COPYRIGHT
82  
83 Copyright 2014 Paul Lockaby. All rights reserved.
84  
85 This library is free software; you can redistribute it and/or modify it under
86 the same terms as Perl itself.
87  
88 =head1 SEE ALSO
89  
90 =over
91  
92 =item
93  
94 L<Prancer>
95  
96 =item
97  
98 L<Log::Log4perl>
99  
100 =item
101  
102 L<Log::Dispatch>
103  
104 =item
105  
106 L<Log::Dispatch::Screen>
107  
108 =back
109  
110 =cut
↑ Summary