File Coverage

blib/lib/Log/Fine/Formatter/Basic.pm
Criterion Covered Total %
statement 26 26 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 35 35 100.0


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   2660 use strict;
  17         31  
  17         610  
39 17     17   105 use warnings;
  17         71  
  17         2018  
40              
41             package Log::Fine::Formatter::Basic;
42              
43 17     17   139 use base qw( Log::Fine::Formatter );
  17         31  
  17         8619  
44              
45 17     17   125 use Log::Fine;
  17         31  
  17         1052  
46 17     17   135 use Log::Fine::Formatter;
  17         32  
  17         369  
47 17     17   94 use Log::Fine::Levels;
  17         31  
  17         745  
48              
49             our $VERSION = $Log::Fine::Formatter::VERSION;
50              
51 17     17   196 use POSIX qw( strftime );
  17         35  
  17         97  
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 38 my $self = shift;
89 17         34 my $lvl = shift;
90 17         37 my $msg = shift;
91 17         28 my $skip = shift; # NOT USED
92              
93             # Return the formatted string
94             return
95 17         131 sprintf("[%s] %-4s %s\n",
96             $self->_formatTime(), $self->levelMap()->valueToLevel($lvl),
97             $msg);
98              
99             } # format()
100              
101             =head1 BUGS
102              
103             Please report any bugs or feature requests to
104             C, or through the web interface at
105             L.
106             I will be notified, and then you'll automatically be notified of progress on
107             your bug as I make changes.
108              
109             =head1 SUPPORT
110              
111             You can find documentation for this module with the perldoc command.
112              
113             perldoc Log::Fine
114              
115             You can also look for information at:
116              
117             =over 4
118              
119             =item * AnnoCPAN: Annotated CPAN documentation
120              
121             L
122              
123             =item * CPAN Ratings
124              
125             L
126              
127             =item * RT: CPAN's request tracker
128              
129             L
130              
131             =item * Search CPAN
132              
133             L
134              
135             =back
136              
137             =head1 AUTHOR
138              
139             Christopher M. Fuhrman, C<< >>
140              
141             =head1 SEE ALSO
142              
143             L, L
144              
145             =head1 COPYRIGHT & LICENSE
146              
147             Copyright (c) 2008-2010, 2013 Christopher M. Fuhrman,
148             All rights reserved.
149              
150             This program is free software licensed under the...
151              
152             The BSD License
153              
154             The full text of the license can be found in the
155             LICENSE file included with this module.
156              
157             =cut
158              
159             1; # End of Log::Fine::Formatter::Basic