| Filename | /appl/netdisco/perl5/lib/perl5/Dancer/Logger.pm |
| Statements | Executed 99 statements in 529µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 33 | 1 | 1 | 262µs | 10.1ms | Dancer::Logger::debug |
| 33 | 1 | 1 | 214µs | 214µs | Dancer::Logger::_serialize |
| 0 | 0 | 0 | 0s | 0s | Dancer::Logger::BEGIN |
| 0 | 0 | 0 | 0s | 0s | Dancer::Logger::core |
| 0 | 0 | 0 | 0s | 0s | Dancer::Logger::error |
| 0 | 0 | 0 | 0s | 0s | Dancer::Logger::info |
| 0 | 0 | 0 | 0s | 0s | Dancer::Logger::init |
| 0 | 0 | 0 | 0s | 0s | Dancer::Logger::logger |
| 0 | 0 | 0 | 0s | 0s | Dancer::Logger::warning |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Dancer::Logger; | ||||
| 2 | our $AUTHORITY = 'cpan:SUKRIA'; | ||||
| 3 | #ABSTRACT: common interface for logging in Dancer | ||||
| 4 | $Dancer::Logger::VERSION = '1.3512'; | ||||
| 5 | # Factory for logger engines | ||||
| 6 | |||||
| 7 | use strict; | ||||
| 8 | use warnings; | ||||
| 9 | use Data::Dumper; | ||||
| 10 | use Dancer::Engine; | ||||
| 11 | |||||
| 12 | # singleton used for logging messages | ||||
| 13 | my $logger; | ||||
| 14 | sub logger {$logger} | ||||
| 15 | |||||
| 16 | sub init { | ||||
| 17 | my ($class, $name, $config) = @_; | ||||
| 18 | $logger = Dancer::Engine->build(logger => $name, $config); | ||||
| 19 | } | ||||
| 20 | |||||
| 21 | # spent 214µs within Dancer::Logger::_serialize which was called 33 times, avg 6µs/call:
# 33 times (214µs+0s) by Dancer::Logger::debug at line 37, avg 6µs/call | ||||
| 22 | 33 | 29µs | my @vars = @_; | ||
| 23 | |||||
| 24 | return join q{}, map { | ||||
| 25 | 33 | 179µs | ref $_ | ||
| 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 | sub core { defined($logger) and $logger->core( _serialize(@_) ) } | ||||
| 37 | 33 | 320µs | 66 | 9.88ms | # spent 10.1ms (262µs+9.88) within Dancer::Logger::debug which was called 33 times, avg 307µs/call:
# 33 times (262µs+9.88ms) by App::Netdisco::Util::Device::_bail_msg at line 141 of Dancer.pm, avg 307µs/call # spent 9.66ms making 33 calls to Dancer::Logger::Abstract::debug, avg 293µs/call
# spent 214µs making 33 calls to Dancer::Logger::_serialize, avg 6µs/call |
| 38 | sub info { defined($logger) and $logger->info( _serialize(@_) ) } | ||||
| 39 | sub warning { defined($logger) and $logger->warning( _serialize(@_) ) } | ||||
| 40 | sub error { defined($logger) and $logger->error( _serialize(@_) ) } | ||||
| 41 | |||||
| 42 | 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.3512 | ||||
| 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__ |