File Coverage

blib/lib/Log/Fine/Levels/Syslog.pm
Criterion Covered Total %
statement 46 46 100.0
branch 2 4 50.0
condition n/a
subroutine 20 20 100.0
pod 9 9 100.0
total 77 79 97.4


line stmt bran cond sub pod time code
1              
2             =head1 NAME
3              
4             Log::Fine::Levels::Syslog - Provides levels correlating to those provided by Syslog
5              
6             =head1 SYNOPSIS
7              
8             Defines log level values and masks correlating to those provided by
9             Syslog.
10              
11             use Log::Fine;
12             use Log::Fine::Levels::Syslog;
13              
14             # Grab a logging object
15             my $log = Log::Fine->getLogger("foo0");
16              
17             # Note that INFO and EMER are provided by the
18             # Log::Fine::Levels::Syslog object
19             $log->log(INFO, "I'm not mad at you, I'm mad at the dirt");
20             $log->log(EMER, "No more wire hangers ... EVER!");
21              
22             Note that this is the default class for L.
23              
24             =head1 DESCRIPTION
25              
26             Log::Fine::Levels::Syslog provides logging and mask constants
27             mimicking those provided by the classic UNIX L utility.
28             This class is also used internally by the L utility for
29             interpreting log levels.
30              
31             =cut
32              
33 19     19   13798 use strict;
  19         41  
  19         835  
34 19     19   107 use warnings;
  19         42  
  19         870  
35              
36             package Log::Fine::Levels::Syslog;
37              
38 19     19   20846 use AutoLoader;
  19         45607  
  19         1241  
39 19     19   768 use Carp;
  19         46  
  19         1556  
40 19     19   157 use Exporter;
  19         42  
  19         1823  
41 19     19   117 use POSIX qw( strftime );
  19         45  
  19         1426  
42              
43 19     19   1235 use base qw/ Log::Fine::Levels Exporter /;
  19         41  
  19         4228  
44              
45             our $VERSION = $Log::Fine::Levels::VERSION;
46              
47             # Necessary for AutoLoader
48             our $AUTOLOAD;
49              
50             =head2 Log Levels
51              
52             Log::Fine::Levels::Syslog bases its log levels on those found in
53             L. The following are exported into the caller
54             namespace:
55              
56             =over 4
57              
58             =item * C
59              
60             =item * C
61              
62             =item * C
63              
64             =item * C
65              
66             =item * C
67              
68             =item * C
69              
70             =item * C
71              
72             =item * C
73              
74             =back
75              
76             =cut
77              
78             # Default level-to-value hash
79 19         4799 use constant LVLTOVAL_MAP => {
80             EMER => 0,
81             ALRT => 1,
82             CRIT => 2,
83             ERR => 3,
84             WARN => 4,
85             NOTI => 5,
86             INFO => 6,
87             DEBG => 7
88 19     19   130 }; # LVLTOVAL_MAP{}
  19         52  
89              
90             # Default value-to-level hash
91 19         4406 use constant VALTOLVL_MAP => {
92             LVLTOVAL_MAP->{EMER} => "EMER",
93             LVLTOVAL_MAP->{ALRT} => "ALRT",
94             LVLTOVAL_MAP->{CRIT} => "CRIT",
95             LVLTOVAL_MAP->{ERR} => "ERR",
96             LVLTOVAL_MAP->{WARN} => "WARN",
97             LVLTOVAL_MAP->{NOTI} => "NOTI",
98             LVLTOVAL_MAP->{INFO} => "INFO",
99             LVLTOVAL_MAP->{DEBG} => "DEBG"
100 19     19   135 }; # VALTOLVL_MAP{}
  19         46  
101              
102             =head2 Log Masks
103              
104             Log masks can be exported for use in setting up individual handles
105             (see L). The following masks are exported into the
106             caller namespace:
107              
108             =over 4
109              
110             =item * C
111              
112             =item * C
113              
114             =item * C
115              
116             =item * C
117              
118             =item * C
119              
120             =item * C
121              
122             =item * C
123              
124             =item * C
125              
126             =back
127              
128             See L for more information.
129              
130             =cut
131              
132 19         11223 use constant MASK_MAP => {
133             LOGMASK_EMERG => 2 << LVLTOVAL_MAP->{EMER},
134             LOGMASK_ALERT => 2 << LVLTOVAL_MAP->{ALRT},
135             LOGMASK_CRIT => 2 << LVLTOVAL_MAP->{CRIT},
136             LOGMASK_ERR => 2 << LVLTOVAL_MAP->{ERR},
137             LOGMASK_WARNING => 2 << LVLTOVAL_MAP->{WARN},
138             LOGMASK_NOTICE => 2 << LVLTOVAL_MAP->{NOTI},
139             LOGMASK_INFO => 2 << LVLTOVAL_MAP->{INFO},
140             LOGMASK_DEBUG => 2 << LVLTOVAL_MAP->{DEBG}
141 19     19   118 }; # MASK_MAP{}
  19         48  
142              
143             # --------------------------------------------------------------------
144              
145             # grab appropriate refs
146             my $levels = LVLTOVAL_MAP;
147             my $masks = MASK_MAP;
148              
149             # Exported tags
150             our %EXPORT_TAGS = (macros => [ keys %{$levels} ],
151             masks => [ keys %{$masks} ]); # EXPORT_TAGS
152              
153             # Exported macros
154             our @EXPORT = (@{ $EXPORT_TAGS{macros} });
155             our @EXPORT_OK = (@{ $EXPORT_TAGS{masks} });
156              
157             # functions okay to export
158             our %ok_fields = (%{$levels}, %{$masks});
159              
160             # --------------------------------------------------------------------
161              
162             =head1 CONSTRUCTOR
163              
164             =head2 new
165              
166             Returns a newly constructed object
167              
168             =cut
169              
170             sub new
171             {
172              
173 17     17 1 76 my $class = shift;
174 17         348 return bless { levelclass => $class }, $class;
175              
176             } # new()
177              
178             # Autoloader
179             # --------------------------------------------------------------------
180              
181             sub AUTOLOAD
182             {
183              
184             # Get the method name
185 48     48   5073 my $name = $AUTOLOAD;
186              
187             # Strip out package prefix
188 48         384 $name =~ s/.*://;
189              
190             # Return on DESTROY
191 48 50       198 return if $name eq 'DESTROY';
192              
193             # Make sure we have a valid function
194 48 50       198 croak(
195             sprintf("[%s] {%s} FATAL : %s\n",
196             strftime("%c", localtime(time)),
197             $AUTOLOAD,
198             "Invalid function name : $name"
199             )) unless (exists $ok_fields{$name});
200              
201             # Evaluate and return the appropriate level
202 48     47 1 5412 eval "sub $name { return $ok_fields{$name} }";
  47     267 1 36775  
  267     167 1 252037  
  167     90 1 137059  
  90     5 1 96579  
  5     2 1 35  
  2     4 1 11  
  4     2 1 36  
  2         27  
203 48         1999 goto &$name;
204              
205             } # AUTOLOAD()
206              
207             =head1 BUGS
208              
209             Please report any bugs or feature requests to
210             C, or through the web interface at
211             L.
212             I will be notified, and then you'll automatically be notified of progress on
213             your bug as I make changes.
214              
215             =head1 SUPPORT
216              
217             You can find documentation for this module with the perldoc command.
218              
219             perldoc Log::Fine::Levels::Syslog
220              
221             You can also look for information at:
222              
223             =over 4
224              
225             =item * AnnoCPAN: Annotated CPAN documentation
226              
227             L
228              
229             =item * CPAN Ratings
230              
231             L
232              
233             =item * RT: CPAN's request tracker
234              
235             L
236              
237             =item * Search CPAN
238              
239             L
240              
241             =back
242              
243             =head1 AUTHOR
244              
245             Christopher M. Fuhrman, C<< >>
246              
247             =head1 SEE ALSO
248              
249             L, L, L, L, L
250              
251             =head1 COPYRIGHT & LICENSE
252              
253             Copyright (c) 2009, 2010, 2013 Christopher M. Fuhrman,
254             All rights reserved.
255              
256             This program is free software licensed under the...
257              
258             The BSD License
259              
260             The full text of the license can be found in the
261             LICENSE file included with this module.
262              
263             =cut
264              
265             1; # End of Log::Fine::Levels::Syslog
266              
267             __END__