lib/Dancer/Logger.pm

filter: Statementstmt 96.3% 26 / 27 Branchbran 57.1% 8 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 7 totaltotal 75.0% 45 / 60 CC 8 SCAR 8.4
CC
8
Cov
83%
info
6.0
_serialize
3.0
debug
2.1
CRAP 2.3
« lib/Dancer/Factory/Hook.pm ↑ Summary blib/lib/Dancer/Plugin.pm »
1 package Dancer::Logger;
2 246 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: common interface for logging in Dancer
4 246 $Dancer::Logger::VERSION = '1.3522';
5 # Factory for logger engines
6  
7 246 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 246 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 246 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 246 ▶use Dancer::Engine;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # singleton used for logging messages
13 246 my $logger;
14 9 ▶sub logger {$logger}
Subroutine logger: called CC=1 SCAR=0.0
Pod undocumented
15  
16 109 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
17 109 my ($class, $name, $config) = @_;
18 109 $logger = Dancer::Engine->build(logger => $name, $config);
19 }
20  
21 3015 ▶sub _serialize {
Subroutine _serialize: called CC=3 SCAR=11.1
22 3015 my @vars = @_;
23  
24 return join q{}, map {
25 3015 ▶ ref $_
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ? : 3 3016 3019
defined $_ ? : 3016 0 3016
26 ? Data::Dumper->new([$_])
27 ->Terse(1)
28 ->Purity(1)
29 ->Indent(0)
30 ->Sortkeys(1)
31 ->Dump()
32 : (defined($_) ? $_ : 'undef')
33 } @vars;
34 }
35  
36 3178 ▶sub core { defined($logger) and $logger->core( _serialize(@_) ) }
Subroutine core: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $logger and $logger->core(_serialize(@_)) 2961 217 3178
37 6 ▶sub debug { defined($logger) and $logger->debug( _serialize(@_) ) }
Subroutine debug: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $logger and $logger->debug(_serialize(@_)) 6 0 6
38 0 ▶sub info { defined($logger) and $logger->info( _serialize(@_) ) }
Subroutine info: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $logger and $logger->info(_serialize(@_)) 0 0 0
39 8 ▶sub warning { defined($logger) and $logger->warning( _serialize(@_) ) }
Subroutine warning: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $logger and $logger->warning(_serialize(@_)) 8 0 8
40 40 ▶sub error { defined($logger) and $logger->error( _serialize(@_) ) }
Subroutine error: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $logger and $logger->error(_serialize(@_)) 40 0 40
41  
42 246 1;
43  
44 =pod
45  
46 =encoding UTF-8
47  
48 =head1 NAME
49  
50 Dancer::Logger - common interface for logging in Dancer
51  
52 =head1 VERSION
53  
54 version 1.3522
55  
56 =head1 DESCRIPTION
57  
58 This module is the wrapper that provides support for different
59 logger engines.
60  
61 =head1 USAGE
62  
63 =head2 Default engine
64  
65 The setting B<logger> defines which logger engine to use.
66 If this setting is not set, logging will not be available in the application
67 code.
68  
69 Dancer comes with the logger engines L<Dancer::Logger::File> and
70 L<Dancer::Logger::Console>, but more are available on the CPAN.
71  
72 =head2 Configuration
73  
74 The B<logger> configuration variable tells Dancer which engine to use.
75  
76 You can change it either in your config.yml file:
77  
78 # logging to console
79 logger: "console"
80  
81 Or in the application code:
82  
83 # logging to file
84 set logger => 'file';
85  
86 The log format can also be configured,
87 please see L<Dancer::Logger::Abstract/"logger_format"> for details.
88  
89 =head2 Auto-serializing
90  
91 The loggers allow auto-serializing of all inputs:
92  
93 debug( 'User credentials: ', \%creds );
94  
95 Will provide you with an output in a single log message of the string and the
96 reference dump.
97  
98 =head1 AUTHORS
99  
100 This module has been written by Alexis Sukrieh. See the AUTHORS file that comes
101 with this distribution for details.
102  
103 =head1 LICENSE
104  
105 This module is free software and is released under the same terms as Perl
106 itself.
107  
108 =head1 SEE ALSO
109  
110 See L<Dancer> for details about the complete framework.
111  
112 You can also search the CPAN for existing engines in the Dancer::Logger
113 namespace : L<http://search.cpan.org/search?query=Dancer%3A%3ALogger>.
114  
115 =head1 AUTHOR
116  
117 Dancer Core Developers
118  
119 =head1 COPYRIGHT AND LICENSE
120  
121 This software is copyright (c) 2010 by Alexis Sukrieh.
122  
123 This is free software; you can redistribute it and/or modify it under
124 the same terms as the Perl 5 programming language system itself.
125  
126 =cut
127  
128 __END__
« lib/Dancer/Factory/Hook.pm ↑ Summary blib/lib/Dancer/Plugin.pm »