File Coverage

blib/lib/Keystone/Resolver/LogLevel.pm
Criterion Covered Total %
statement 39 39 100.0
branch 5 8 62.5
condition n/a
subroutine 20 20 100.0
pod 17 18 94.4
total 81 85 95.2


line stmt bran cond sub pod time code
1             # $Id: LogLevel.pm,v 1.5 2008-03-26 14:43:25 mike Exp $
2              
3             package Keystone::Resolver::LogLevel;
4              
5 5     5   6368 use strict;
  5         18  
  5         169  
6 5     5   25 use warnings;
  5         8  
  5         3015  
7              
8              
9             =head1 NAME
10              
11             Keystone::Resolver::LogLevel - logging levels for Keystone Resolver
12              
13             =head1 SYNOPSIS
14              
15             $resolver->option(loglevel => (Keystone::Resolver::LogLevel::CHITCHAT &
16             Keystone::Resolver::LogLevel::CACHECHECK));
17             print Keystone::Resolver::LogLevel::label(Keystone::Resolver::LogLevel::PARSEXSLT);
18              
19             =head1 DESCRIPTION
20              
21             This trivial class supplies a set of symbolic constants for the
22             bitmasks used in log-levels for Keystone Resolver logs. These may be
23             arithmetrically ORred together to provide the resolver with a
24             requested logging level consisting of more than one of the levels
25             defined here.
26              
27             =head1 LOGGING LEVELS
28              
29             =over 4
30              
31             =item CHITCHAT
32              
33             Notify events of general interest such as starting up and shutting
34             down. (DEADLY WARNING: Only use this if you like that kind of thing.)
35              
36             =item CACHECHECK
37              
38             Notify when checking for the existence of any kind of object in a
39             cache.
40              
41             =item PARSEXSLT
42              
43             Notify when parsing an XSLT stylesheet.
44              
45             =item DUMPDESCRIPTORS
46              
47             Dump the contents of the parsed descriptors.
48              
49             =item SHOWGENRE
50              
51             Dump the referent object before trying to resolve it.
52              
53             =item SHOWGENRE
54              
55             Show the genre (both ID and name) of each object resolved.
56              
57             =item DBLOOKUP
58              
59             Show the results of looking up IDs and tags in the resource database.
60              
61             =item MKRESULT
62              
63             Show the results of looking up IDs and tags in the resource database.
64              
65             =item SQL
66              
67             Show SQL statements before executing them.
68              
69             =item DEREFERENCE
70              
71             Indicate when an element of an OpenURL is dereferenced. This includes
72             both a By-Reference ContextObject, and individual entities that are
73             specified by reference.
74              
75             =item DISSECT
76              
77             Indicate when a By-Value OpenURL (including one in which that value
78             was fetched because it was originally By-Reference) is dissected into
79             KEV elements.
80              
81             =item RESOLVEID
82              
83             Indicate when any kind of identifier (DOI, PubMed ID, etc.) is
84             resolved, and what the results are.
85              
86             =item CONVERT01
87              
88             Log the conversion of OpenURL v0.1 parameters to their v1.0
89             equivalents, and the creation of additional parameters required by
90             v1.0.
91              
92             =item HANDLE
93              
94             Indicate when a service handles a request, and whether the result is a
95             usable URL or a fatal or non-fatal error.
96              
97             =item WARNING
98              
99             Warnings generated by bad recipes and suchlike.
100              
101             =item LIFECYCLE
102              
103             Information about the creation and destruction of objects such as
104             resolvers and databases, whether explicit or garbage-collected.
105              
106             =back
107              
108             =cut
109              
110 6     6 1 133 sub CHITCHAT { 0x1 }
111 6     6 1 17 sub CACHECHECK { 0x2 }
112 5     5 1 13 sub PARSEXSLT { 0x4 }
113 5     5 1 14 sub DUMPDESCRIPTORS { 0x8 }
114 5     5 0 19 sub DUMPREFERENT { 0x10 }
115 5     5 1 16 sub SHOWGENRE { 0x20 }
116 6     6 1 18 sub DBLOOKUP { 0x40 }
117 6     6 1 14 sub MKRESULT { 0x80 }
118 6     6 1 18 sub SQL { 0x100 }
119 5     5 1 13 sub DEREFERENCE { 0x200 }
120 5     5 1 28 sub DISSECT { 0x400 }
121 5     5 1 11 sub RESOLVEID { 0x800 }
122 5     5 1 16 sub CONVERT01 { 0x1000 }
123 6     6 1 18 sub HANDLE { 0x2000 }
124 7     7 1 17 sub WARNING { 0x4000 }
125 6     6 1 48 sub LIFECYCLE { 0x8000 }
126              
127              
128             =head1 METHODS
129              
130             =cut
131              
132              
133             =head2 num()
134              
135             print Keystone::Resolver::LogLevel::num("parsexslt,sql");
136              
137             Returns a numeric value representing the comma-separated set of
138             logging levels listed in the argument -- namely, the sum of the values
139             corresponding to each individual level. It is a fatal error to
140             include an undefined logging-level name.
141              
142             =cut
143              
144             my %str2num = (
145             CHITCHAT => CHITCHAT,
146             CACHECHECK => CACHECHECK,
147             PARSEXSLT => PARSEXSLT,
148             DUMPDESCRIPTORS => DUMPDESCRIPTORS,
149             DUMPREFERENT => DUMPREFERENT,
150             SHOWGENRE => SHOWGENRE,
151             DBLOOKUP => DBLOOKUP,
152             MKRESULT => MKRESULT,
153             SQL => SQL,
154             DEREFERENCE => DEREFERENCE,
155             DISSECT => DISSECT,
156             RESOLVEID => RESOLVEID,
157             CONVERT01 => CONVERT01,
158             HANDLE => HANDLE,
159             WARNING => WARNING,
160             LIFECYCLE => LIFECYCLE,
161             );
162              
163             sub num {
164 6     6 1 270 my($str) = @_;
165              
166 6         9 my $num = 0;
167 6         20 foreach my $comp (split /,/, uc($str)) {
168 9         16 my $val = $str2num{$comp};
169 9 50       18 die "no loglevel called '$comp'" if !defined $val;
170 9         15 $num += $val;
171             }
172              
173 6         18 return $num;
174             }
175              
176              
177             =head2 label()
178              
179             print Keystone::Resolver::LogLevel::label(Resolver::LogLevel::PARSEXSLT |
180             Resolver::LogLevel::SQL);
181              
182             Returns a short human-readable string describing the combination of
183             logging-levels specified as the argument.
184              
185             =cut
186              
187             my %num2str = reverse %str2num;
188              
189             sub label {
190 6     6 1 6 my($level) = @_;
191              
192 6         7 my @res;
193              
194 6         10 foreach my $exp (0..31) {
195 192         154 my $val = 1 << $exp;
196 192 100       311 if ($level & $val) {
197 9         13 my $str = $num2str{$val};
198 9 50       23 die "no loglevel string for 1<<$exp == $val" if !defined $str;
199 9         11 push @res, $str;
200             }
201             }
202              
203 6 50       23 return "[empty]" if @res == 0;
204 6         23 return join(",", @res);
205             }
206              
207              
208             1;