File Coverage

blib/lib/Dancer/Logger.pm
Criterion Covered Total %
statement 22 23 95.6
branch 7 14 50.0
condition n/a
subroutine 11 12 91.6
pod 0 7 0.0
total 40 56 71.4


line stmt bran cond sub pod time code
1             package Dancer::Logger;
2             our $AUTHORITY = 'cpan:SUKRIA';
3             #ABSTRACT: common interface for logging in Dancer
4             $Dancer::Logger::VERSION = '1.3514_04'; # TRIAL
5             $Dancer::Logger::VERSION = '1.351404';
6             # Factory for logger engines
7              
8 195     195   1626 use strict;
  195         404  
  195         4567  
9 195     195   888 use warnings;
  195         394  
  195         3904  
10 195     195   95470 use Data::Dumper;
  195         1021373  
  195         11685  
11 195     195   2965 use Dancer::Engine;
  195         392  
  195         48693  
12              
13             # singleton used for logging messages
14             my $logger;
15 9     9 0 2513 sub logger {$logger}
16              
17             sub init {
18 109     109 0 1082 my ($class, $name, $config) = @_;
19 109         495 $logger = Dancer::Engine->build(logger => $name, $config);
20             }
21              
22             sub _serialize {
23 3019     3019   4787 my @vars = @_;
24              
25             return join q{}, map {
26 3019 50       4269 ref $_
  3022 50       13251  
27             ? Data::Dumper->new([$_])
28             ->Terse(1)
29             ->Purity(1)
30             ->Indent(0)
31             ->Sortkeys(1)
32             ->Dump()
33             : (defined($_) ? $_ : 'undef')
34             } @vars;
35             }
36              
37 3174 100   3174 0 8335 sub core { defined($logger) and $logger->core( _serialize(@_) ) }
38 6 50   6 0 521 sub debug { defined($logger) and $logger->debug( _serialize(@_) ) }
39 0 0   0 0 0 sub info { defined($logger) and $logger->info( _serialize(@_) ) }
40 4 50   4 0 374 sub warning { defined($logger) and $logger->warning( _serialize(@_) ) }
41 40 50   40 0 527 sub error { defined($logger) and $logger->error( _serialize(@_) ) }
42              
43             1;
44              
45             =pod
46              
47             =encoding UTF-8
48              
49             =head1 NAME
50              
51             Dancer::Logger - common interface for logging in Dancer
52              
53             =head1 VERSION
54              
55             version 1.3514_04
56              
57             =head1 DESCRIPTION
58              
59             This module is the wrapper that provides support for different
60             logger engines.
61              
62             =head1 USAGE
63              
64             =head2 Default engine
65              
66             The setting B defines which logger engine to use.
67             If this setting is not set, logging will not be available in the application
68             code.
69              
70             Dancer comes with the logger engines L and
71             L, but more are available on the CPAN.
72              
73             =head2 Configuration
74              
75             The B configuration variable tells Dancer which engine to use.
76              
77             You can change it either in your config.yml file:
78              
79             # logging to console
80             logger: "console"
81              
82             Or in the application code:
83              
84             # logging to file
85             set logger => 'file';
86              
87             The log format can also be configured,
88             please see L for details.
89              
90             =head2 Auto-serializing
91              
92             The loggers allow auto-serializing of all inputs:
93              
94             debug( 'User credentials: ', \%creds );
95              
96             Will provide you with an output in a single log message of the string and the
97             reference dump.
98              
99             =head1 AUTHORS
100              
101             This module has been written by Alexis Sukrieh. See the AUTHORS file that comes
102             with this distribution for details.
103              
104             =head1 LICENSE
105              
106             This module is free software and is released under the same terms as Perl
107             itself.
108              
109             =head1 SEE ALSO
110              
111             See L for details about the complete framework.
112              
113             You can also search the CPAN for existing engines in the Dancer::Logger
114             namespace : L.
115              
116             =head1 AUTHOR
117              
118             Dancer Core Developers
119              
120             =head1 COPYRIGHT AND LICENSE
121              
122             This software is copyright (c) 2010 by Alexis Sukrieh.
123              
124             This is free software; you can redistribute it and/or modify it under
125             the same terms as the Perl 5 programming language system itself.
126              
127             =cut
128              
129             __END__