| 1 | # $Id: LogLevel.pm,v 1.5 2008-03-26 14:43:25 mike Exp $ | ||||||||||
| 2 | |||||||||||
| 3 | package Keystone::Resolver::LogLevel; | ||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | ▶ | sub CHITCHAT { 0x1 } | ||||||||
|
Subroutine
CHITCHAT: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 111 | 6 | ▶ | sub CACHECHECK { 0x2 } | ||||||||
|
Subroutine
CACHECHECK: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 112 | 5 | ▶ | sub PARSEXSLT { 0x4 } | ||||||||
|
Subroutine
PARSEXSLT: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 113 | 5 | ▶ | sub DUMPDESCRIPTORS { 0x8 } | ||||||||
|
Subroutine
DUMPDESCRIPTORS: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 114 | 5 | ▶ | sub DUMPREFERENT { 0x10 } | ||||||||
|
Subroutine
DUMPREFERENT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 115 | 5 | ▶ | sub SHOWGENRE { 0x20 } | ||||||||
|
Subroutine
SHOWGENRE: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 116 | 6 | ▶ | sub DBLOOKUP { 0x40 } | ||||||||
|
Subroutine
DBLOOKUP: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 117 | 6 | ▶ | sub MKRESULT { 0x80 } | ||||||||
|
Subroutine
MKRESULT: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 118 | 6 | ▶ | sub SQL { 0x100 } | ||||||||
|
Subroutine
SQL: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 119 | 5 | ▶ | sub DEREFERENCE { 0x200 } | ||||||||
|
Subroutine
DEREFERENCE: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 120 | 5 | ▶ | sub DISSECT { 0x400 } | ||||||||
|
Subroutine
DISSECT: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 121 | 5 | ▶ | sub RESOLVEID { 0x800 } | ||||||||
|
Subroutine
RESOLVEID: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 122 | 5 | ▶ | sub CONVERT01 { 0x1000 } | ||||||||
|
Subroutine
CONVERT01: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 123 | 6 | ▶ | sub HANDLE { 0x2000 } | ||||||||
|
Subroutine
HANDLE: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 124 | 7 | ▶ | sub WARNING { 0x4000 } | ||||||||
|
Subroutine
WARNING: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 125 | 6 | ▶ | sub LIFECYCLE { 0x8000 } | ||||||||
|
Subroutine
LIFECYCLE: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 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 | 5 | 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 | 6 | ▶ | sub num { | ||||||||
|
Subroutine
num: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 164 | 6 | my($str) = @_; | |||||||||
| 165 | |||||||||||
| 166 | 6 | my $num = 0; | |||||||||
| 167 | 6 | foreach my $comp (split /,/, uc($str)) { | |||||||||
| 168 | 9 | my $val = $str2num{$comp}; | |||||||||
| 169 | 9 | ▶ | die "no loglevel called '$comp'" if !defined $val; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 170 | 9 | $num += $val; | |||||||||
| 171 | } | ||||||||||
| 172 | |||||||||||
| 173 | 6 | 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 | 5 | my %num2str = reverse %str2num; | |||||||||
| 188 | |||||||||||
| 189 | 6 | ▶ | sub label { | ||||||||
|
Subroutine
label: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||
| 190 | 6 | my($level) = @_; | |||||||||
| 191 | |||||||||||
| 192 | 6 | my @res; | |||||||||
| 193 | |||||||||||
| 194 | 6 | foreach my $exp (0..31) { | |||||||||
| 195 | 192 | my $val = 1 << $exp; | |||||||||
| 196 | 192 | ▶ | if ($level & $val) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 197 | 9 | my $str = $num2str{$val}; | |||||||||
| 198 | 9 | ▶ | die "no loglevel string for 1<<$exp == $val" if !defined $str; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 199 | 9 | push @res, $str; | |||||||||
| 200 | } | ||||||||||
| 201 | } | ||||||||||
| 202 | |||||||||||
| 203 | 6 | ▶ | return "[empty]" if @res == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 204 | 6 | return join(",", @res); | |||||||||
| 205 | } | ||||||||||
| 206 | |||||||||||
| 207 | |||||||||||
| 208 | 5 | 1; | |||||||||