Filename | /usr/local/lib/site_perl/Log/Core/Essentials.pm |
Statements | Executed 92 statements in 1.07ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5 | 1 | 1 | 45µs | 53µs | severity_as_str | Log::Core::Essentials::
1 | 1 | 1 | 12µs | 15µs | BEGIN@2 | Log::Core::Essentials::
1 | 1 | 1 | 11µs | 36µs | BEGIN@112 | Log::Core::Essentials::
1 | 1 | 1 | 11µs | 35µs | BEGIN@113 | Log::Core::Essentials::
1 | 1 | 1 | 9µs | 33µs | BEGIN@107 | Log::Core::Essentials::
1 | 1 | 1 | 9µs | 32µs | BEGIN@117 | Log::Core::Essentials::
1 | 1 | 1 | 7µs | 42µs | BEGIN@67 | Log::Core::Essentials::
1 | 1 | 1 | 7µs | 39µs | BEGIN@99 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 31µs | BEGIN@114 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 31µs | BEGIN@101 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 28µs | BEGIN@68 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 30µs | BEGIN@110 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 30µs | BEGIN@116 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 30µs | BEGIN@111 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 31µs | BEGIN@100 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 11µs | BEGIN@3 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 31µs | BEGIN@106 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 30µs | BEGIN@104 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 36µs | BEGIN@79 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 30µs | BEGIN@103 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 30µs | BEGIN@115 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 30µs | BEGIN@118 | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 33µs | BEGIN@105 | Log::Core::Essentials::
5 | 1 | 1 | 6µs | 6µs | CORE:match (opcode) | Log::Core::Essentials::
1 | 1 | 1 | 6µs | 33µs | BEGIN@102 | Log::Core::Essentials::
1 | 1 | 1 | 4µs | 4µs | BEGIN@78 | Log::Core::Essentials::
1 | 1 | 1 | 2µs | 2µs | END | Log::Core::Essentials::
0 | 0 | 0 | 0s | 0s | severities | Log::Core::Essentials::
0 | 0 | 0 | 0s | 0s | severity_as_int | Log::Core::Essentials::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Log::Core::Essentials; | ||||
2 | 2 | 21µs | 2 | 18µs | # spent 15µs (12+3) within Log::Core::Essentials::BEGIN@2 which was called:
# once (12µs+3µs) by Log::Loger::BEGIN@116 at line 2 # spent 15µs making 1 call to Log::Core::Essentials::BEGIN@2
# spent 3µs making 1 call to strict::import |
3 | 2 | 56µs | 2 | 15µs | # spent 11µs (6+4) within Log::Core::Essentials::BEGIN@3 which was called:
# once (6µs+4µs) by Log::Loger::BEGIN@116 at line 3 # spent 11µs making 1 call to Log::Core::Essentials::BEGIN@3
# spent 4µs making 1 call to warnings::import |
4 | |||||
5 | #******************************************************************************* | ||||
6 | # | ||||
7 | # DOCUMENTATION SECTION | ||||
8 | # | ||||
9 | #******************************************************************************* | ||||
10 | |||||
11 | =head1 NAME | ||||
12 | |||||
13 | Log::Core::Essentials - Essential methods and constants for whole logging framework | ||||
14 | |||||
15 | =head1 SYNOPSIS | ||||
16 | |||||
17 | use Log::Core::Essentials; | ||||
18 | |||||
19 | # Get list of all valid severity values | ||||
20 | my @severities = Log::Core::Essentials->severities(); | ||||
21 | |||||
22 | # Translate given severity into integer representation | ||||
23 | my $result = Log::Core::Essentials->severity_as_int('EMERG'); | ||||
24 | |||||
25 | # Translate given severity into string representation | ||||
26 | my $result = Log::Core::Essentials->severity_as_str(4); | ||||
27 | |||||
28 | =head1 DESCRIPTION | ||||
29 | |||||
30 | This class contains essential contants for whole logging framework, and | ||||
31 | methods for converting message severities from string to their integer | ||||
32 | representations, and vice versa. | ||||
33 | |||||
34 | =head1 AUTHOR | ||||
35 | |||||
36 | Jan Mach | ||||
37 | Cesnet, z.s.p.o | ||||
38 | jan.mach@cesnet.cz | ||||
39 | http://www.cesnet.cz | ||||
40 | |||||
41 | =head1 COPYRIGHT | ||||
42 | |||||
43 | This program is free software; you can redistribute | ||||
44 | it and/or modify it under the same terms as Perl itself. | ||||
45 | |||||
46 | The full text of the license can be found in the | ||||
47 | LICENSE file included with this module. | ||||
48 | |||||
49 | |||||
50 | =head1 SEE ALSO | ||||
51 | |||||
52 | perl(1). | ||||
53 | |||||
54 | =head1 FUNCTION REFERENCE | ||||
55 | |||||
56 | =over 4 | ||||
57 | |||||
58 | =cut | ||||
59 | |||||
60 | #******************************************************************************* | ||||
61 | # | ||||
62 | # INITIALIZATION AND CLEANUP SECTION | ||||
63 | # | ||||
64 | #******************************************************************************* | ||||
65 | |||||
66 | #-- Perl core modules ---------------------------------------------------------# | ||||
67 | 2 | 24µs | 2 | 77µs | # spent 42µs (7+35) within Log::Core::Essentials::BEGIN@67 which was called:
# once (7µs+35µs) by Log::Loger::BEGIN@116 at line 67 # spent 42µs making 1 call to Log::Core::Essentials::BEGIN@67
# spent 35µs making 1 call to Exporter::import |
68 | 2 | 31µs | 2 | 50µs | # spent 28µs (6+22) within Log::Core::Essentials::BEGIN@68 which was called:
# once (6µs+22µs) by Log::Loger::BEGIN@116 at line 68 # spent 28µs making 1 call to Log::Core::Essentials::BEGIN@68
# spent 22µs making 1 call to Exporter::import |
69 | |||||
70 | #use Data::Dumper; #-+-> DEVEL ONLY <-+-# | ||||
71 | #use Smart::Comments; #-+-> DEVEL ONLY <-+-# | ||||
72 | |||||
73 | #-- Perl CPAN modules ---------------------------------------------------------# | ||||
74 | |||||
75 | #-- Custom application modules ------------------------------------------------# | ||||
76 | |||||
77 | #-- Module initializations ----------------------------------------------------# | ||||
78 | # spent 4µs within Log::Core::Essentials::BEGIN@78 which was called:
# once (4µs+0s) by Log::Loger::BEGIN@116 at line 82 | ||||
79 | 2 | 28µs | 2 | 66µs | # spent 36µs (6+30) within Log::Core::Essentials::BEGIN@79 which was called:
# once (6µs+30µs) by Log::Loger::BEGIN@116 at line 79 # spent 36µs making 1 call to Log::Core::Essentials::BEGIN@79
# spent 30µs making 1 call to vars::import |
80 | 1 | 400ns | $VERSION = '0.01'; | ||
81 | 1 | 3µs | $DEVEL = 0; | ||
82 | 1 | 37µs | 1 | 4µs | } # spent 4µs making 1 call to Log::Core::Essentials::BEGIN@78 |
83 | |||||
84 | |||||
85 | #-- Module clean-up code (global destructor) ----------------------------------# | ||||
86 | 1 | 2µs | # spent 2µs within Log::Core::Essentials::END which was called:
# once (2µs+0s) by main::RUNTIME at line 0 of mentat.storage.mongo.pl | ||
87 | |||||
88 | } | ||||
89 | |||||
90 | #******************************************************************************* | ||||
91 | # | ||||
92 | # CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION | ||||
93 | # | ||||
94 | #******************************************************************************* | ||||
95 | |||||
96 | #-- Constants -----------------------------------------------------------------# | ||||
97 | |||||
98 | # Log severity integer values | ||||
99 | 2 | 25µs | 2 | 72µs | # spent 39µs (7+33) within Log::Core::Essentials::BEGIN@99 which was called:
# once (7µs+33µs) by Log::Loger::BEGIN@116 at line 99 # spent 39µs making 1 call to Log::Core::Essentials::BEGIN@99
# spent 33µs making 1 call to constant::import |
100 | 2 | 28µs | 2 | 57µs | # spent 31µs (6+25) within Log::Core::Essentials::BEGIN@100 which was called:
# once (6µs+25µs) by Log::Loger::BEGIN@116 at line 100 # spent 31µs making 1 call to Log::Core::Essentials::BEGIN@100
# spent 25µs making 1 call to constant::import |
101 | 2 | 22µs | 2 | 56µs | # spent 31µs (6+25) within Log::Core::Essentials::BEGIN@101 which was called:
# once (6µs+25µs) by Log::Loger::BEGIN@116 at line 101 # spent 31µs making 1 call to Log::Core::Essentials::BEGIN@101
# spent 25µs making 1 call to constant::import |
102 | 2 | 25µs | 2 | 61µs | # spent 33µs (6+28) within Log::Core::Essentials::BEGIN@102 which was called:
# once (6µs+28µs) by Log::Loger::BEGIN@116 at line 102 # spent 33µs making 1 call to Log::Core::Essentials::BEGIN@102
# spent 28µs making 1 call to constant::import |
103 | 2 | 22µs | 2 | 54µs | # spent 30µs (6+24) within Log::Core::Essentials::BEGIN@103 which was called:
# once (6µs+24µs) by Log::Loger::BEGIN@116 at line 103 # spent 30µs making 1 call to Log::Core::Essentials::BEGIN@103
# spent 24µs making 1 call to constant::import |
104 | 2 | 22µs | 2 | 53µs | # spent 30µs (6+23) within Log::Core::Essentials::BEGIN@104 which was called:
# once (6µs+23µs) by Log::Loger::BEGIN@116 at line 104 # spent 30µs making 1 call to Log::Core::Essentials::BEGIN@104
# spent 24µs making 1 call to constant::import |
105 | 2 | 23µs | 2 | 60µs | # spent 33µs (6+27) within Log::Core::Essentials::BEGIN@105 which was called:
# once (6µs+27µs) by Log::Loger::BEGIN@116 at line 105 # spent 33µs making 1 call to Log::Core::Essentials::BEGIN@105
# spent 27µs making 1 call to constant::import |
106 | 2 | 25µs | 2 | 55µs | # spent 31µs (6+25) within Log::Core::Essentials::BEGIN@106 which was called:
# once (6µs+25µs) by Log::Loger::BEGIN@116 at line 106 # spent 31µs making 1 call to Log::Core::Essentials::BEGIN@106
# spent 24µs making 1 call to constant::import |
107 | 2 | 25µs | 2 | 58µs | # spent 33µs (9+24) within Log::Core::Essentials::BEGIN@107 which was called:
# once (9µs+24µs) by Log::Loger::BEGIN@116 at line 107 # spent 33µs making 1 call to Log::Core::Essentials::BEGIN@107
# spent 24µs making 1 call to constant::import |
108 | |||||
109 | # Log severity string values | ||||
110 | 2 | 23µs | 2 | 54µs | # spent 30µs (6+24) within Log::Core::Essentials::BEGIN@110 which was called:
# once (6µs+24µs) by Log::Loger::BEGIN@116 at line 110 # spent 30µs making 1 call to Log::Core::Essentials::BEGIN@110
# spent 24µs making 1 call to constant::import |
111 | 2 | 27µs | 2 | 53µs | # spent 30µs (6+23) within Log::Core::Essentials::BEGIN@111 which was called:
# once (6µs+23µs) by Log::Loger::BEGIN@116 at line 111 # spent 30µs making 1 call to Log::Core::Essentials::BEGIN@111
# spent 24µs making 1 call to constant::import |
112 | 2 | 24µs | 2 | 61µs | # spent 36µs (11+25) within Log::Core::Essentials::BEGIN@112 which was called:
# once (11µs+25µs) by Log::Loger::BEGIN@116 at line 112 # spent 36µs making 1 call to Log::Core::Essentials::BEGIN@112
# spent 25µs making 1 call to constant::import |
113 | 2 | 24µs | 2 | 59µs | # spent 35µs (11+24) within Log::Core::Essentials::BEGIN@113 which was called:
# once (11µs+24µs) by Log::Loger::BEGIN@116 at line 113 # spent 35µs making 1 call to Log::Core::Essentials::BEGIN@113
# spent 24µs making 1 call to constant::import |
114 | 2 | 23µs | 2 | 56µs | # spent 31µs (6+25) within Log::Core::Essentials::BEGIN@114 which was called:
# once (6µs+25µs) by Log::Loger::BEGIN@116 at line 114 # spent 31µs making 1 call to Log::Core::Essentials::BEGIN@114
# spent 25µs making 1 call to constant::import |
115 | 2 | 23µs | 2 | 53µs | # spent 30µs (6+24) within Log::Core::Essentials::BEGIN@115 which was called:
# once (6µs+24µs) by Log::Loger::BEGIN@116 at line 115 # spent 30µs making 1 call to Log::Core::Essentials::BEGIN@115
# spent 24µs making 1 call to constant::import |
116 | 2 | 23µs | 2 | 53µs | # spent 30µs (6+24) within Log::Core::Essentials::BEGIN@116 which was called:
# once (6µs+24µs) by Log::Loger::BEGIN@116 at line 116 # spent 30µs making 1 call to Log::Core::Essentials::BEGIN@116
# spent 24µs making 1 call to constant::import |
117 | 2 | 23µs | 2 | 56µs | # spent 32µs (9+24) within Log::Core::Essentials::BEGIN@117 which was called:
# once (9µs+24µs) by Log::Loger::BEGIN@116 at line 117 # spent 32µs making 1 call to Log::Core::Essentials::BEGIN@117
# spent 24µs making 1 call to constant::import |
118 | 2 | 395µs | 2 | 54µs | # spent 30µs (6+24) within Log::Core::Essentials::BEGIN@118 which was called:
# once (6µs+24µs) by Log::Loger::BEGIN@116 at line 118 # spent 30µs making 1 call to Log::Core::Essentials::BEGIN@118
# spent 24µs making 1 call to constant::import |
119 | |||||
120 | #-- Static public class variables (our) ---------------------------------------# | ||||
121 | |||||
122 | #-- Static protected class variables (my) -------------------------------------# | ||||
123 | |||||
124 | # Translation table from string severity labels to integer representations | ||||
125 | # We MUST NOT USE '=>' symbol in the hash definition, otherwise the constant | ||||
126 | # names left of it would be automatically quoted and interpreted as strings. | ||||
127 | 1 | 4µs | my %SEVERITY2INT = ( EMAIL_STR , EMAIL, | ||
128 | EMERG_STR , EMERG, | ||||
129 | ALERT_STR , ALERT, | ||||
130 | CRIT_STR , CRIT, | ||||
131 | ERROR_STR , ERROR, | ||||
132 | WARNING_STR , WARNING, | ||||
133 | NOTICE_STR , NOTICE, | ||||
134 | INFO_STR , INFO, | ||||
135 | DEBUG_STR , DEBUG, | ||||
136 | ); | ||||
137 | |||||
138 | # Translation table from integer representations to string severity labels | ||||
139 | 1 | 2µs | my @INT2SEVERITY = ( DEBUG_STR, | ||
140 | INFO_STR, | ||||
141 | NOTICE_STR, | ||||
142 | WARNING_STR, | ||||
143 | ERROR_STR, | ||||
144 | CRIT_STR, | ||||
145 | ALERT_STR, | ||||
146 | EMERG_STR, | ||||
147 | EMAIL_STR, | ||||
148 | ); | ||||
149 | |||||
150 | #******************************************************************************* | ||||
151 | # | ||||
152 | # IMPLEMENTATION SECTION | ||||
153 | # | ||||
154 | #******************************************************************************* | ||||
155 | |||||
156 | =item severities() [PUBLIC,STATIC] | ||||
157 | |||||
158 | Usage : Log::Core::Essentials->severities(); | ||||
159 | Purpose : Get list of all valid severities | ||||
160 | Arguments : None | ||||
161 | Returns : ARRAY of STRINGS @severities | ||||
162 | Throws : Croaks, if not invoked on class | ||||
163 | |||||
164 | =cut | ||||
165 | |||||
166 | sub severities() | ||||
167 | { | ||||
168 | my $class = shift; | ||||
169 | croak ((caller(0))[3] . ": class method invoked on object") if blessed($class); | ||||
170 | return @INT2SEVERITY; | ||||
171 | } | ||||
172 | |||||
173 | =item severity_as_int($) [PUBLIC,STATIC] | ||||
174 | |||||
175 | Usage : Log::Core::Essentials->severity_as_int('DEBUG') | ||||
176 | Purpose : Convert severity value in integer or string into corresponding integer value | ||||
177 | Arguments : MIXED $severity - integer or string severity to convert, strings are case insensitive | ||||
178 | Returns : UNDEF on FAILURE, INTEGER representation of given severity on SUCCESS | ||||
179 | Throws : Croaks, if not invoked on class | ||||
180 | |||||
181 | =cut | ||||
182 | |||||
183 | sub severity_as_int($) | ||||
184 | { | ||||
185 | my $class = shift; | ||||
186 | croak ((caller(0))[3] . ": class method invoked on object") if blessed($class); | ||||
187 | my ($severity,) = @_; | ||||
188 | |||||
189 | # Return undefined value if severity was not specified | ||||
190 | return undef unless (defined($severity)); | ||||
191 | |||||
192 | # Perform conversion to integer only if the argument is empty string or not a number | ||||
193 | if ($severity =~ /^$|[^\d]+/) { | ||||
194 | $severity = $SEVERITY2INT{uc($severity)}; | ||||
195 | } | ||||
196 | |||||
197 | # Return undefined value if the integer is not a valid severity value | ||||
198 | return undef unless (defined($severity) and defined($INT2SEVERITY[$severity])); | ||||
199 | |||||
200 | # Othervise return valid value | ||||
201 | return $severity; | ||||
202 | } | ||||
203 | |||||
204 | =item severity_as_str [PUBLIC,STATIC] | ||||
205 | |||||
206 | Usage : Log::Core::Essentials->severity_as_str(7) | ||||
207 | Purpose : Convert severity value in integer or string into corresponding string value | ||||
208 | Arguments : MIXED $severity - integer or string severity to convert, strings are case insensitive | ||||
209 | Returns : UNDEF on FAILURE, STRING representation of given severity on SUCCESS | ||||
210 | Throws : Croaks, if not invoked on class | ||||
211 | |||||
212 | =cut | ||||
213 | |||||
214 | sub severity_as_str($) | ||||
215 | # spent 53µs (45+8) within Log::Core::Essentials::severity_as_str which was called 5 times, avg 11µs/call:
# 5 times (45µs+8µs) by Log::Loger::log at line 484 of Log/Loger.pm, avg 11µs/call | ||||
216 | 5 | 2µs | my $class = shift; | ||
217 | 5 | 16µs | 5 | 3µs | croak ((caller(0))[3] . ": class method invoked on object") if blessed($class); # spent 3µs making 5 calls to Scalar::Util::blessed, avg 540ns/call |
218 | 5 | 2µs | my ($severity,) = @_; | ||
219 | |||||
220 | # Return undefined value if severity was not specified | ||||
221 | 5 | 900ns | return undef unless (defined($severity)); | ||
222 | |||||
223 | # Normalize the severity to the uppercase | ||||
224 | 5 | 3µs | $severity = uc($severity); | ||
225 | |||||
226 | # Perform conversion only if the argument is a number | ||||
227 | 5 | 17µs | 5 | 6µs | if ($severity =~ /[\d]+/) { # spent 6µs making 5 calls to Log::Core::Essentials::CORE:match, avg 1µs/call |
228 | $severity = $INT2SEVERITY[int($severity)]; | ||||
229 | } | ||||
230 | |||||
231 | # Return undefined value if the integer is not a valid severity value | ||||
232 | 5 | 4µs | return undef unless (defined($severity) and defined($SEVERITY2INT{$severity})); | ||
233 | |||||
234 | # Othervise return valid value | ||||
235 | 5 | 11µs | return $severity; | ||
236 | } | ||||
237 | |||||
238 | =pod | ||||
239 | |||||
240 | =back | ||||
241 | |||||
242 | =cut | ||||
243 | |||||
244 | 1 | 4µs | 1; | ||
# spent 6µs within Log::Core::Essentials::CORE:match which was called 5 times, avg 1µs/call:
# 5 times (6µs+0s) by Log::Core::Essentials::severity_as_str at line 227, avg 1µs/call |