ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Log.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Log.pm (file contents):
Revision 1.66 by root, Mon Mar 11 20:48:19 2019 UTC vs.
Revision 1.70 by root, Tue Sep 3 11:46:29 2019 UTC

8 8
9 use AnyEvent; 9 use AnyEvent;
10 10
11 AE::log fatal => "No config found, cannot continue!"; # never returns 11 AE::log fatal => "No config found, cannot continue!"; # never returns
12 AE::log alert => "The battery died!"; 12 AE::log alert => "The battery died!";
13 AE::log crit => "The battery temperature is too hot!"; 13 AE::log crit => "The battery is too hot!";
14 AE::log error => "Division by zero attempted."; 14 AE::log error => "Division by zero attempted.";
15 AE::log warn => "Couldn't delete the file."; 15 AE::log warn => "Couldn't delete the file.";
16 AE::log note => "Wanted to create config, but config already exists."; 16 AE::log note => "Attempted to create config, but config already exists.";
17 AE::log info => "File soandso successfully deleted."; 17 AE::log info => "File soandso successfully deleted.";
18 AE::log debug => "the function returned 3"; 18 AE::log debug => "the function returned 3";
19 AE::log trace => "going to call function abc"; 19 AE::log trace => "going to call function abc";
20 20
21Log level overview: 21Log level overview:
40 $tracer->("i am here") if $trace; 40 $tracer->("i am here") if $trace;
41 $tracer->(sub { "lots of data: " . Dumper $self }) if $trace; 41 $tracer->(sub { "lots of data: " . Dumper $self }) if $trace;
42 42
43Configuration (also look at the EXAMPLES section): 43Configuration (also look at the EXAMPLES section):
44 44
45 # set default logging level to suppress anything below "notice"
46 # i.e. enable logging at "notice" or above - the default is to
47 # to not log anything at all.
48 $AnyEvent::Log::FILTER->level ("notice");
49
45 # set logging for the current package to errors and higher only 50 # set logging for the current package to errors and higher only
46 AnyEvent::Log::ctx->level ("error"); 51 AnyEvent::Log::ctx->level ("error");
47 52
48 # set logging level to suppress anything below "notice" 53 # enable logging for the current package, regardless of global logging level
49 $AnyEvent::Log::FILTER->level ("notice"); 54 AnyEvent::Log::ctx->attach ($AnyEvent::Log::LOG);
55
56 # enable debug logging for module some::mod and enable logging by default
57 (AnyEvent::Log::ctx "some::mod")->level ("debug");
58 (AnyEvent::Log::ctx "some::mod")->attach ($AnyEvent::Log::LOG);
50 59
51 # send all critical and higher priority messages to syslog, 60 # send all critical and higher priority messages to syslog,
52 # regardless of (most) other settings 61 # regardless of (most) other settings
53 $AnyEvent::Log::COLLECT->attach (new AnyEvent::Log::Ctx 62 $AnyEvent::Log::COLLECT->attach (new AnyEvent::Log::Ctx
54 level => "critical", 63 level => "critical",
585 594
586=item $ctx = AnyEvent::Log::ctx [$pkg] 595=item $ctx = AnyEvent::Log::ctx [$pkg]
587 596
588This function creates or returns a logging context (which is an object). 597This function creates or returns a logging context (which is an object).
589 598
590If a package name is given, then the context for that packlage is 599If a package name is given, then the context for that package is
591returned. If it is called without any arguments, then the context for the 600returned. If it is called without any arguments, then the context for the
592callers package is returned (i.e. the same context as a C<AE::log> call 601callers package is returned (i.e. the same context as a C<AE::log> call
593would use). 602would use).
594 603
595If C<undef> is given, then it creates a new anonymous context that is not 604If C<undef> is given, then it creates a new anonymous context that is not
875sub attach { 884sub attach {
876 my $ctx = shift; 885 my $ctx = shift;
877 886
878 $ctx->[2]{$_+0} = $_ 887 $ctx->[2]{$_+0} = $_
879 for map { AnyEvent::Log::ctx $_ } @_; 888 for map { AnyEvent::Log::ctx $_ } @_;
889 AnyEvent::Log::_reassess;
880} 890}
881 891
882sub detach { 892sub detach {
883 my $ctx = shift; 893 my $ctx = shift;
884 894
885 delete $ctx->[2]{$_+0} 895 delete $ctx->[2]{$_+0}
886 for map { AnyEvent::Log::ctx $_ } @_; 896 for map { AnyEvent::Log::ctx $_ } @_;
897 AnyEvent::Log::_reassess;
887} 898}
888 899
889sub slaves { 900sub slaves {
890 undef $_[0][2]; 901 undef $_[0][2];
891 &attach; 902 &attach;
903 AnyEvent::Log::_reassess;
892} 904}
893 905
894=back 906=back
895 907
896=head3 LOG TARGETS 908=head3 LOG TARGETS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines