… | |
… | |
20 | $tracer->("i am here") if $trace; |
20 | $tracer->("i am here") if $trace; |
21 | $tracer->(sub { "lots of data: " . Dumper $self }) if $trace; |
21 | $tracer->(sub { "lots of data: " . Dumper $self }) if $trace; |
22 | |
22 | |
23 | # configuration |
23 | # configuration |
24 | |
24 | |
25 | # set logging for this package to maximum |
25 | # set logging for this package to errors and higher only |
26 | AnyEvent::Log::ctx->level ("all"); |
26 | AnyEvent::Log::ctx->level ("error"); |
27 | |
27 | |
28 | # set logging globally to anything below debug |
28 | # set logging globally to anything below debug |
29 | (AnyEvent::Log::ctx "")->level ("notice"); |
29 | $AnyEvent::Log::Root->level ("notice"); |
30 | |
30 | |
31 | # see also EXAMPLES, below |
31 | # see also EXAMPLES, below |
32 | |
|
|
33 | # disable logging for package "AnyEvent" and all packages below it |
|
|
34 | AnyEvent->AnyEvent::Log::ctx->level (0); |
|
|
35 | |
|
|
36 | # log everything below debug to a file, for the whole program |
|
|
37 | my $ctx = AnyEvent::Log::ctx; |
|
|
38 | $ctx->log_cb (sub { print FILE shift; 0 }); |
|
|
39 | (AnyEvent::Log::ctx "")->add ($ctx); |
|
|
40 | |
32 | |
41 | =head1 DESCRIPTION |
33 | =head1 DESCRIPTION |
42 | |
34 | |
43 | This module implements a relatively simple "logging framework". It doesn't |
35 | This module implements a relatively simple "logging framework". It doesn't |
44 | attempt to be "the" logging solution or even "a" logging solution for |
36 | attempt to be "the" logging solution or even "a" logging solution for |
… | |
… | |
280 | # and later in your program |
272 | # and later in your program |
281 | $debug_log->("yo, stuff here") if $debug; |
273 | $debug_log->("yo, stuff here") if $debug; |
282 | |
274 | |
283 | $debug and $debug_log->("123"); |
275 | $debug and $debug_log->("123"); |
284 | |
276 | |
285 | Note: currently the enabled var is always true - that will be fixed in a |
|
|
286 | future version :) |
|
|
287 | |
|
|
288 | =cut |
277 | =cut |
289 | |
278 | |
290 | our %LOGGER; |
279 | our %LOGGER; |
291 | |
280 | |
292 | # re-assess logging status for all loggers |
281 | # re-assess logging status for all loggers |
… | |
… | |
456 | : bless [undef, (1 << 10) - 1 - 1], "AnyEvent::Log::Ctx" |
445 | : bless [undef, (1 << 10) - 1 - 1], "AnyEvent::Log::Ctx" |
457 | } |
446 | } |
458 | |
447 | |
459 | =item AnyEvent::Log::reset |
448 | =item AnyEvent::Log::reset |
460 | |
449 | |
461 | Resets all package contexts contexts and recreates the default hierarchy |
450 | Resets all package contexts and recreates the default hierarchy if |
462 | if necessary, i.e. resets the logging subsystem to defaults. |
451 | necessary, i.e. resets the logging subsystem to defaults, as much as |
|
|
452 | possible. This process keeps references to contexts held by other parts of |
|
|
453 | the program intact. |
463 | |
454 | |
464 | This can be used to implement config-file (re-)loading: before loading a |
455 | This can be used to implement config-file (re-)loading: before loading a |
465 | configuration, reset all contexts. |
456 | configuration, reset all contexts. |
466 | |
|
|
467 | Note that this currently destroys all logger callbacks - bug me if you |
|
|
468 | need this fixed :) |
|
|
469 | |
457 | |
470 | =cut |
458 | =cut |
471 | |
459 | |
472 | sub reset { |
460 | sub reset { |
473 | # hard to kill complex data structures |
461 | # hard to kill complex data structures |