… | |
… | |
12 | attempt to be "the" logging solution or even "a" logging solution for |
12 | attempt to be "the" logging solution or even "a" logging solution for |
13 | AnyEvent - AnyEvent simply creates logging messages internally, and this |
13 | AnyEvent - AnyEvent simply creates logging messages internally, and this |
14 | module more or less exposes the mechanism, with some extra spiff to allow |
14 | module more or less exposes the mechanism, with some extra spiff to allow |
15 | using it from other modules as well. |
15 | using it from other modules as well. |
16 | |
16 | |
17 | Remember that the default verbosity level is C<0>, so nothing |
17 | Remember that the default verbosity level is C<0>, so nothing will be |
18 | will be logged, ever, unless you set C<$Anyvent::VERBOSE> or |
18 | logged, ever, unless you set C<PERL_ANYEVENT_VERBOSE> to a higher number |
19 | C<PERL_ANYEVENT_VERBOSE> to a higher number. |
19 | before starting your program.#TODO |
20 | |
20 | |
21 | Possible future extensions are to allow custom log targets (where the |
21 | Possible future extensions are to allow custom log targets (where the |
22 | level is an object), log filtering based on package, formatting, aliasing |
22 | level is an object), log filtering based on package, formatting, aliasing |
23 | or package groups. |
23 | or package groups. |
24 | |
24 | |
… | |
… | |
52 | if $now_int != $i; |
52 | if $now_int != $i; |
53 | |
53 | |
54 | "$now_str1$f$now_str2" |
54 | "$now_str1$f$now_str2" |
55 | } |
55 | } |
56 | |
56 | |
57 | our %CFG; #TODO |
57 | our %CTX; # all logging contexts |
58 | |
58 | |
59 | =item AnyEvent::Log::log $level, $msg[, @args] |
59 | =item AnyEvent::Log::log $level, $msg[, @args] |
60 | |
60 | |
61 | Requests logging of the given C<$msg> with the given log level (1..9). |
61 | Requests logging of the given C<$msg> with the given log level (1..9). |
62 | You can also use the following strings as log level: C<fatal> (1), |
62 | You can also use the following strings as log level: C<fatal> (1), |
… | |
… | |
254 | |
254 | |
255 | None, yet, except for C<PERL_ANYEVENT_VERBOSE>, described in the L<AnyEvent> manpage. |
255 | None, yet, except for C<PERL_ANYEVENT_VERBOSE>, described in the L<AnyEvent> manpage. |
256 | |
256 | |
257 | =over 4 |
257 | =over 4 |
258 | |
258 | |
|
|
259 | =item $ctx = AnyEvent::Log::ctx [$pkg] |
|
|
260 | |
|
|
261 | Returns the I<context> object for the given package name (or previously |
|
|
262 | created package-less context). If no package name, or C<undef>, is given, |
|
|
263 | then it creates a new anonymous context that is not tied to any package. |
|
|
264 | |
259 | =cut |
265 | =cut |
|
|
266 | |
|
|
267 | sub ctx(;$) { |
|
|
268 | my $name = shift; |
|
|
269 | |
|
|
270 | my $ctx = defined $name ? $CTX{$name} : undef; |
|
|
271 | |
|
|
272 | unless ($ctx} { |
|
|
273 | $ctx = bless {}, "AnyEvent::Log::Ctx"; |
|
|
274 | $name = $ctx+0 unless defined $name; |
|
|
275 | $CTX{ |
|
|
276 | |
|
|
277 | if (defined $name) { |
|
|
278 | my $ctx = {}; |
|
|
279 | $CTX{$ctx+0} = $ctx; |
|
|
280 | } else { |
|
|
281 | $CTX{ |
|
|
282 | } |
|
|
283 | } |
260 | |
284 | |
261 | 1; |
285 | 1; |
262 | |
286 | |
263 | =back |
287 | =back |
264 | |
288 | |