| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | =head1 NAME | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | Log::Fine::Formatter::Basic - Default logging formatter | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | Formats log messages for output in a basic format, suitable for most | 
| 9 |  |  |  |  |  |  | applications. | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | use Log::Fine::Formatter::Basic; | 
| 12 |  |  |  |  |  |  | use Log::Fine::Handle::Console; | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | # Instantiate a handle | 
| 15 |  |  |  |  |  |  | my $handle = Log::Fine::Handle::Console->new(); | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | # Instantiate a formatter | 
| 18 |  |  |  |  |  |  | my $formatter = Log::Fine::Formatter::Basic | 
| 19 |  |  |  |  |  |  | ->new( name             => 'basic0', | 
| 20 |  |  |  |  |  |  | timestamp_format => "%y-%m-%d %h:%m:%s" ); | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | # Set the formatter | 
| 23 |  |  |  |  |  |  | $handle->formatter( formatter => $formatter ); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | # Format a msg | 
| 26 |  |  |  |  |  |  | my $str = $formatter->format(INFO, "Resistance is futile", 1); | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | The basic formatter provides logging in the following format: | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | <[TIMESTAMP] | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | Note that this is the default format for L objects. | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =cut | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 17 |  |  | 17 |  | 1390 | use strict; | 
|  | 17 |  |  |  |  | 18 |  | 
|  | 17 |  |  |  |  | 375 |  | 
| 39 | 17 |  |  | 17 |  | 45 | use warnings; | 
|  | 17 |  |  |  |  | 13 |  | 
|  | 17 |  |  |  |  | 473 |  | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | package Log::Fine::Formatter::Basic; | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 17 |  |  | 17 |  | 74 | use base qw( Log::Fine::Formatter ); | 
|  | 17 |  |  |  |  | 14 |  | 
|  | 17 |  |  |  |  | 4398 |  | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 17 |  |  | 17 |  | 60 | use Log::Fine; | 
|  | 17 |  |  |  |  | 20 |  | 
|  | 17 |  |  |  |  | 235 |  | 
| 46 | 17 |  |  | 17 |  | 45 | use Log::Fine::Formatter; | 
|  | 17 |  |  |  |  | 17 |  | 
|  | 17 |  |  |  |  | 218 |  | 
| 47 | 17 |  |  | 17 |  | 46 | use Log::Fine::Levels; | 
|  | 17 |  |  |  |  | 15 |  | 
|  | 17 |  |  |  |  | 532 |  | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | our $VERSION = $Log::Fine::Formatter::VERSION; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 17 |  |  | 17 |  | 66 | use POSIX qw( strftime ); | 
|  | 17 |  |  |  |  | 14 |  | 
|  | 17 |  |  |  |  | 59 |  | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | =head1 METHODS | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =head2 format | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | Formats the given message for the given level | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head3 Parameters | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =over | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =item  * level | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | Level at which to log (see L) | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =item  * message | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | Message to log | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =item  * skip | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | [ignored] Controls caller skip level | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =back | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =head3 Returns | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | The formatted text string in the form: | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | [TIMESTAMP] LEVEL MESSAGE | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =cut | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | sub format | 
| 86 |  |  |  |  |  |  | { | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 17 |  |  | 17 | 1 | 22 | my $self = shift; | 
| 89 | 17 |  |  |  |  | 16 | my $lvl  = shift; | 
| 90 | 17 |  |  |  |  | 17 | my $msg  = shift; | 
| 91 | 17 |  |  |  |  | 14 | my $skip = shift;          # NOT USED | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | # Return the formatted string | 
| 94 | 17 |  |  |  |  | 80 | return sprintf("[%s] %-4s %s\n", $self->_formatTime(), $self->levelMap()->valueToLevel($lvl), $msg); | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | }          # format() | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =head1 BUGS | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | Please report any bugs or feature requests to | 
| 101 |  |  |  |  |  |  | C, or through the web interface at | 
| 102 |  |  |  |  |  |  | L. | 
| 103 |  |  |  |  |  |  | I will be notified, and then you'll automatically be notified of progress on | 
| 104 |  |  |  |  |  |  | your bug as I make changes. | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | =head1 SUPPORT | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | You can find documentation for this module with the perldoc command. | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | perldoc Log::Fine | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | You can also look for information at: | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =over 4 | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | L | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | L | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | =item * RT: CPAN's request tracker | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | L | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | =item * Search CPAN | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | L | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | =back | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | =head1 AUTHOR | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | Christopher M. Fuhrman, C<<  >> | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | L, L | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | Copyright (c) 2008-2010, 2013 Christopher M. Fuhrman, | 
| 145 |  |  |  |  |  |  | All rights reserved. | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | This program is free software licensed under the... | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | The BSD License | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | The full text of the license can be found in the | 
| 152 |  |  |  |  |  |  | LICENSE file included with this module. | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | =cut | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | 1;          # End of Log::Fine::Formatter::Basic |