File Coverage

blib/lib/Log/Fine/Levels/Java.pm
Criterion Covered Total %
statement 50 50 100.0
branch 2 4 50.0
condition n/a
subroutine 24 24 100.0
pod 13 13 100.0
total 89 91 97.8


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