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.43 by root, Mon Sep 5 07:21:54 2011 UTC vs.
Revision 1.52 by root, Thu Mar 22 19:27:30 2012 UTC

6 6
7Simple uses: 7Simple uses:
8 8
9 use AnyEvent; 9 use AnyEvent;
10 10
11 AE::log debug => "hit my knee"; 11 AE::log fatal => "no config found, cannot continue"; # never returns
12 AE::log warn => "it's a bit too hot"; 12 AE::log alert => "the battery died";
13 AE::log error => "the flag was false!"; 13 AE::log crit => "the battery temperature is too hot";
14 AE::log fatal => "the bit toggled! run!"; # never returns 14 AE::log error => "division by zero attempted";
15 AE::log warn => "couldn't delete the file";
16 AE::log note => "wanted to create config, but config already exists";
17 AE::log info => "file soandso successfully deleted";
18 AE::log debug => "the function returned 3";
19 AE::log trace => "going to call function abc";
15 20
16 # available log levels in order: 21Log level overview:
17 # fatal alert critical error warn note info debug trace
18
19"Complex" uses (for speed sensitive code):
20
21 use AnyEvent::Log;
22
23 my $tracer = AnyEvent::Log::logger trace => \$my $trace;
24
25 $tracer->("i am here") if $trace;
26 $tracer->(sub { "lots of data: " . Dumper $self }) if $trace;
27
28Configuration (also look at the EXAMPLES section):
29
30 # set logging for the current package to errors and higher only
31 AnyEvent::Log::ctx->level ("error");
32
33 # set logging level to suppress anything below "notice"
34 $AnyEvent::Log::FILTER->level ("notice");
35
36 # send all critical and higher priority messages to syslog,
37 # regardless of (most) other settings
38 $AnyEvent::Log::COLLECT->attach (new AnyEvent::Log::Ctx
39 level => "critical",
40 log_to_syslog => "user",
41 );
42
43=head1 DESCRIPTION
44
45This module implements a relatively simple "logging framework". It doesn't
46attempt to be "the" logging solution or even "a" logging solution for
47AnyEvent - AnyEvent simply creates logging messages internally, and this
48module more or less exposes the mechanism, with some extra spiff to allow
49using it from other modules as well.
50
51Remember that the default verbosity level is C<0> (C<off>), so nothing
52will be logged, unless you set C<PERL_ANYEVENT_VERBOSE> to a higher number
53before starting your program, or change the logging level at runtime with
54something like:
55
56 use AnyEvent::Log;
57 $AnyEvent::Log::FILTER->level ("info");
58
59The design goal behind this module was to keep it simple (and small),
60but make it powerful enough to be potentially useful for any module, and
61extensive enough for the most common tasks, such as logging to multiple
62targets, or being able to log into a database.
63
64The module is also usable before AnyEvent itself is initialised, in which
65case some of the functionality might be reduced.
66
67The amount of documentation might indicate otherwise, but the runtime part
68of the module is still just below 300 lines of code.
69
70=head1 LOGGING LEVELS
71
72Logging levels in this module range from C<1> (highest priority) to C<9>
73(lowest priority). Note that the lowest numerical value is the highest
74priority, so when this document says "higher priority" it means "lower
75numerical value".
76
77Instead of specifying levels by name you can also specify them by aliases:
78 22
79 LVL NAME SYSLOG PERL NOTE 23 LVL NAME SYSLOG PERL NOTE
80 1 fatal emerg exit system unusable, aborts program! 24 1 fatal emerg exit system unusable, aborts program!
81 2 alert failure in primary system 25 2 alert failure in primary system
82 3 critical crit failure in backup system 26 3 critical crit failure in backup system
85 6 note notice unusual conditions 29 6 note notice unusual conditions
86 7 info normal messages, no action required 30 7 info normal messages, no action required
87 8 debug debugging messages for development 31 8 debug debugging messages for development
88 9 trace copious tracing output 32 9 trace copious tracing output
89 33
34"Complex" uses (for speed sensitive code, e.g. trace/debug messages):
35
36 use AnyEvent::Log;
37
38 my $tracer = AnyEvent::Log::logger trace => \$my $trace;
39
40 $tracer->("i am here") if $trace;
41 $tracer->(sub { "lots of data: " . Dumper $self }) if $trace;
42
43Configuration (also look at the EXAMPLES section):
44
45 # set logging for the current package to errors and higher only
46 AnyEvent::Log::ctx->level ("error");
47
48 # set logging level to suppress anything below "notice"
49 $AnyEvent::Log::FILTER->level ("notice");
50
51 # send all critical and higher priority messages to syslog,
52 # regardless of (most) other settings
53 $AnyEvent::Log::COLLECT->attach (new AnyEvent::Log::Ctx
54 level => "critical",
55 log_to_syslog => "user",
56 );
57
58=head1 DESCRIPTION
59
60This module implements a relatively simple "logging framework". It doesn't
61attempt to be "the" logging solution or even "a" logging solution for
62AnyEvent - AnyEvent simply creates logging messages internally, and this
63module more or less exposes the mechanism, with some extra spiff to allow
64using it from other modules as well.
65
66Remember that the default verbosity level is C<4> (C<error>), so only
67errors and more important messages will be logged, unless you set
68C<PERL_ANYEVENT_VERBOSE> to a higher number before starting your program
69(C<AE_VERBOSE=5> is recommended during development), or change the logging
70level at runtime with something like:
71
72 use AnyEvent::Log;
73 $AnyEvent::Log::FILTER->level ("info");
74
75The design goal behind this module was to keep it simple (and small),
76but make it powerful enough to be potentially useful for any module, and
77extensive enough for the most common tasks, such as logging to multiple
78targets, or being able to log into a database.
79
80The module is also usable before AnyEvent itself is initialised, in which
81case some of the functionality might be reduced.
82
83The amount of documentation might indicate otherwise, but the runtime part
84of the module is still just below 300 lines of code.
85
86=head1 LOGGING LEVELS
87
88Logging levels in this module range from C<1> (highest priority) to C<9>
89(lowest priority). Note that the lowest numerical value is the highest
90priority, so when this document says "higher priority" it means "lower
91numerical value".
92
93Instead of specifying levels by name you can also specify them by aliases:
94
95 LVL NAME SYSLOG PERL NOTE
96 1 fatal emerg exit system unusable, aborts program!
97 2 alert failure in primary system
98 3 critical crit failure in backup system
99 4 error err die non-urgent program errors, a bug
100 5 warn warning possible problem, not necessarily error
101 6 note notice unusual conditions
102 7 info normal messages, no action required
103 8 debug debugging messages for development
104 9 trace copious tracing output
105
90As you can see, some logging levels have multiple aliases - the first one 106As you can see, some logging levels have multiple aliases - the first one
91is the "official" name, the second one the "syslog" name (if it differs) 107is the "official" name, the second one the "syslog" name (if it differs)
92and the third one the "perl" name, suggesting (only!) that you log C<die> 108and the third one the "perl" name, suggesting (only!) that you log C<die>
93messages at C<error> priority. The NOTE column tries to provide some 109messages at C<error> priority. The NOTE column tries to provide some
94rationale on how to chose a logging level. 110rationale on how to chose a logging level.
95 111
96As a rough guideline, levels 1..3 are primarily meant for users of 112As a rough guideline, levels 1..3 are primarily meant for users of the
97the program (admins, staff), and are the only logged to STDERR by 113program (admins, staff), and are the only ones logged to STDERR by
98default. Levels 4..6 are meant for users and developers alike, while 114default. Levels 4..6 are meant for users and developers alike, while
99levels 7..9 are usually meant for developers. 115levels 7..9 are usually meant for developers.
100 116
101You can normally only log a single message at highest priority level 117You can normally only log a message once at highest priority level (C<1>,
102(C<1>, C<fatal>), because logging a fatal message will also quit the 118C<fatal>), because logging a fatal message will also quit the program - so
103program - so use it sparingly :) 119use it sparingly :)
120
121For example, a program that finds an unknown switch on the commandline
122might well use a fatal logging level to tell users about it - the "system"
123in this case would be the program, or module.
104 124
105Some methods also offer some extra levels, such as C<0>, C<off>, C<none> 125Some methods also offer some extra levels, such as C<0>, C<off>, C<none>
106or C<all> - these are only valid in the methods they are documented for. 126or C<all> - these are only valid for the methods that documented them.
107 127
108=head1 LOGGING FUNCTIONS 128=head1 LOGGING FUNCTIONS
109 129
110These functions allow you to log messages. They always use the caller's 130The following functions allow you to log messages. They always use the
111package as a "logging context". Also, the main logging function C<log> is 131caller's package as a "logging context". Also, the main logging function,
112callable as C<AnyEvent::log> or C<AE::log> when the C<AnyEvent> module is 132C<log>, is aliased to C<AnyEvent::log> and C<AE::log> when the C<AnyEvent>
113loaded. 133module is loaded.
114 134
115=over 4 135=over 4
116 136
117=cut 137=cut
118 138
119package AnyEvent::Log; 139package AnyEvent::Log;
120 140
121use Carp (); 141use Carp ();
122use POSIX (); 142use POSIX ();
143
144# layout of a context
145# 0 1 2 3 4, 5
146# [$title, $level, %$slaves, &$logcb, &$fmtcb, $cap]
123 147
124use AnyEvent (); BEGIN { AnyEvent::common_sense } 148use AnyEvent (); BEGIN { AnyEvent::common_sense }
125#use AnyEvent::Util (); need to load this in a delayed fashion, as it uses AE::log 149#use AnyEvent::Util (); need to load this in a delayed fashion, as it uses AE::log
126 150
127our $VERSION = $AnyEvent::VERSION; 151our $VERSION = $AnyEvent::VERSION;
172 196
173Last not least, C<$msg> might be a code reference, in which case it is 197Last not least, C<$msg> might be a code reference, in which case it is
174supposed to return the message. It will be called only then the message 198supposed to return the message. It will be called only then the message
175actually gets logged, which is useful if it is costly to create the 199actually gets logged, which is useful if it is costly to create the
176message in the first place. 200message in the first place.
201
202This function takes care of saving and restoring C<$!> and C<$@>, so you
203don't have to.
177 204
178Whether the given message will be logged depends on the maximum log level 205Whether the given message will be logged depends on the maximum log level
179and the caller's package. The return value can be used to ensure that 206and the caller's package. The return value can be used to ensure that
180messages or not "lost" - for example, when L<AnyEvent::Debug> detects a 207messages or not "lost" - for example, when L<AnyEvent::Debug> detects a
181runtime error it tries to log it at C<die> level, but if that message is 208runtime error it tries to log it at C<die> level, but if that message is
262 ? $level+0 289 ? $level+0
263 : $STR2LEVEL{$level} || Carp::croak "$level: not a valid logging level, caught"; 290 : $STR2LEVEL{$level} || Carp::croak "$level: not a valid logging level, caught";
264 291
265 my $mask = 1 << $level; 292 my $mask = 1 << $level;
266 293
267 my ($success, %seen, @ctx, $now, $fmt); 294 my ($success, %seen, @ctx, $now, @fmt);
268 295
269 do 296 do
270 { 297 {
271 # skip if masked 298 # if !ref, then it's a level number
299 if (!ref $ctx) {
300 $level = $ctx;
272 if ($ctx->[1] & $mask && !$seen{$ctx+0}++) { 301 } elsif ($ctx->[1] & $mask and !$seen{$ctx+0}++) {
302 # logging/recursing into this context
303
304 # level cap
305 if ($ctx->[5] > $level) {
306 push @ctx, $level; # restore level when going up in tree
307 $level = $ctx->[5];
308 }
309
310 # log if log cb
273 if ($ctx->[3]) { 311 if ($ctx->[3]) {
274 # logging target found 312 # logging target found
313
314 local ($!, $@);
275 315
276 # now get raw message, unless we have it already 316 # now get raw message, unless we have it already
277 unless ($now) { 317 unless ($now) {
278 $format = $format->() if ref $format; 318 $format = $format->() if ref $format;
279 $format = sprintf $format, @args if @args; 319 $format = sprintf $format, @args if @args;
282 }; 322 };
283 323
284 # format msg 324 # format msg
285 my $str = $ctx->[4] 325 my $str = $ctx->[4]
286 ? $ctx->[4]($now, $_[0], $level, $format) 326 ? $ctx->[4]($now, $_[0], $level, $format)
287 : ($fmt ||= _format $now, $_[0], $level, $format); 327 : ($fmt[$level] ||= _format $now, $_[0], $level, $format);
288 328
289 $success = 1; 329 $success = 1;
290 330
291 $ctx->[3]($str) 331 $ctx->[3]($str)
292 or push @ctx, values %{ $ctx->[2] }; # not consumed - propagate 332 or push @ctx, values %{ $ctx->[2] }; # not consumed - propagate
596package AnyEvent::Log::COLLECT; 636package AnyEvent::Log::COLLECT;
597package AE::Log::COLLECT; 637package AE::Log::COLLECT;
598 638
599package AnyEvent::Log::Ctx; 639package AnyEvent::Log::Ctx;
600 640
601# 0 1 2 3 4
602# [$title, $level, %$slaves, &$logcb, &$fmtcb]
603
604=item $ctx = new AnyEvent::Log::Ctx methodname => param... 641=item $ctx = new AnyEvent::Log::Ctx methodname => param...
605 642
606This is a convenience constructor that makes it simpler to construct 643This is a convenience constructor that makes it simpler to construct
607anonymous logging contexts. 644anonymous logging contexts.
608 645
695 732
696=item $ctx->disable ($level[, $level...]) 733=item $ctx->disable ($level[, $level...])
697 734
698Disables logging for the given levels, leaving all others unchanged. 735Disables logging for the given levels, leaving all others unchanged.
699 736
737=item $ctx->cap ($level)
738
739Caps the maximum priority to the given level, for all messages logged
740to, or passing through, this context. That is, while this doesn't affect
741whether a message is logged or passed on, the maximum priority of messages
742will be limited to the specified level - messages with a higher priority
743will be set to the specified priority.
744
745Another way to view this is that C<< ->level >> filters out messages with
746a too low priority, while C<< ->cap >> modifies messages with a too high
747priority.
748
749This is useful when different log targets have different interpretations
750of priority. For example, for a specific command line program, a wrong
751command line switch might well result in a C<fatal> log message, while the
752same message, logged to syslog, is likely I<not> fatal to the system or
753syslog facility as a whole, but more likely a mere C<error>.
754
755This can be modeled by having a stderr logger that logs messages "as-is"
756and a syslog logger that logs messages with a level cap of, say, C<error>,
757or, for truly system-critical components, actually C<critical>.
758
700=cut 759=cut
701 760
702sub _lvl_lst { 761sub _lvl_lst {
703 map { 762 map {
704 $_ > 0 && $_ <= 9 ? $_+0 763 $_ > 0 && $_ <= 9 ? $_+0
705 : $_ eq "all" ? (1 .. 9) 764 : $_ eq "all" ? (1 .. 9)
706 : $STR2LEVEL{$_} || Carp::croak "$_: not a valid logging level, caught" 765 : $STR2LEVEL{$_} || Carp::croak "$_: not a valid logging level, caught"
707 } @_ 766 } @_
708} 767}
709 768
769sub _lvl {
770 $_[0] =~ /^(?:0|off|none)$/ ? 0 : (_lvl_lst $_[0])[-1]
771}
772
710our $NOP_CB = sub { 0 }; 773our $NOP_CB = sub { 0 };
711 774
712sub levels { 775sub levels {
713 my $ctx = shift; 776 my $ctx = shift;
714 $ctx->[1] = 0; 777 $ctx->[1] = 0;
717 AnyEvent::Log::_reassess; 780 AnyEvent::Log::_reassess;
718} 781}
719 782
720sub level { 783sub level {
721 my $ctx = shift; 784 my $ctx = shift;
722 my $lvl = $_[0] =~ /^(?:0|off|none)$/ ? 0 : (_lvl_lst $_[0])[-1];
723
724 $ctx->[1] = ((1 << $lvl) - 1) << 1; 785 $ctx->[1] = ((1 << &_lvl) - 1) << 1;
725 AnyEvent::Log::_reassess; 786 AnyEvent::Log::_reassess;
726} 787}
727 788
728sub enable { 789sub enable {
729 my $ctx = shift; 790 my $ctx = shift;
737 $ctx->[1] &= ~(1 << $_) 798 $ctx->[1] &= ~(1 << $_)
738 for &_lvl_lst; 799 for &_lvl_lst;
739 AnyEvent::Log::_reassess; 800 AnyEvent::Log::_reassess;
740} 801}
741 802
803sub cap {
804 my $ctx = shift;
805 $ctx->[5] = &_lvl;
806}
807
742=back 808=back
743 809
744=head3 SLAVE CONTEXTS 810=head3 SLAVE CONTEXTS
745 811
746The following methods attach and detach another logging context to a 812The following methods attach and detach another logging context to a
833 899
834Replaces the formatting callback on the context (C<undef> restores the 900Replaces the formatting callback on the context (C<undef> restores the
835default formatter). 901default formatter).
836 902
837The callback is passed the (possibly fractional) timestamp, the original 903The callback is passed the (possibly fractional) timestamp, the original
838logging context, the (numeric) logging level and the raw message string 904logging context (object, not title), the (numeric) logging level and
839and needs to return a formatted log message. In most cases this will be a 905the raw message string and needs to return a formatted log message. In
840string, but it could just as well be an array reference that just stores 906most cases this will be a string, but it could just as well be an array
841the values. 907reference that just stores the values.
842 908
843If, for some reason, you want to use C<caller> to find out more baout the 909If, for some reason, you want to use C<caller> to find out more about the
844logger then you should walk up the call stack until you are no longer 910logger then you should walk up the call stack until you are no longer
845inside the C<AnyEvent::Log> package. 911inside the C<AnyEvent::Log> package.
846 912
847Example: format just the raw message, with numeric log level in angle 913Example: format just the raw message, with numeric log level in angle
848brackets. 914brackets.
852 918
853 "<$lvl>$msg\n" 919 "<$lvl>$msg\n"
854 }); 920 });
855 921
856Example: return an array reference with just the log values, and use 922Example: return an array reference with just the log values, and use
857C<PApp::SQL::sql_exec> to store the emssage in a database. 923C<PApp::SQL::sql_exec> to store the message in a database.
858 924
859 $ctx->fmt_cb (sub { \@_ }); 925 $ctx->fmt_cb (sub { \@_ });
860 $ctx->log_cb (sub { 926 $ctx->log_cb (sub {
861 my ($msg) = @_; 927 my ($msg) = @_;
862 928
980 1046
981=item $ctx->log ($level, $msg[, @params]) 1047=item $ctx->log ($level, $msg[, @params])
982 1048
983Same as C<AnyEvent::Log::log>, but uses the given context as log context. 1049Same as C<AnyEvent::Log::log>, but uses the given context as log context.
984 1050
1051Example: log a message in the context of another package.
1052
1053 (AnyEvent::Log::ctx "Other::Package")->log (warn => "heely bo");
1054
985=item $logger = $ctx->logger ($level[, \$enabled]) 1055=item $logger = $ctx->logger ($level[, \$enabled])
986 1056
987Same as C<AnyEvent::Log::logger>, but uses the given context as log 1057Same as C<AnyEvent::Log::logger>, but uses the given context as log
988context. 1058context.
989 1059
1076=item C<nolog> 1146=item C<nolog>
1077 1147
1078Configures the context to not log anything by itself, which is the 1148Configures the context to not log anything by itself, which is the
1079default. Same as C<< $ctx->log_cb (undef) >>. 1149default. Same as C<< $ctx->log_cb (undef) >>.
1080 1150
1151=item C<cap=>I<level>
1152
1153Caps logging messages entering this context at the given level, i.e.
1154reduces the priority of messages with higher priority than this level. The
1155default is C<0> (or C<off>), meaning the priority will not be touched.
1156
1081=item C<0> or C<off> 1157=item C<0> or C<off>
1082 1158
1083Sets the logging level of the context ot C<0>, i.e. all messages will be 1159Sets the logging level of the context to C<0>, i.e. all messages will be
1084filtered out. 1160filtered out.
1085 1161
1086=item C<all> 1162=item C<all>
1087 1163
1088Enables all logging levels, i.e. filtering will effectively be switched 1164Enables all logging levels, i.e. filtering will effectively be switched
1130 1206
1131Attaches the named context as slave to the context. 1207Attaches the named context as slave to the context.
1132 1208
1133=item C<+> 1209=item C<+>
1134 1210
1135A line C<+> detaches all contexts, i.e. clears the slave list from the 1211A lone C<+> detaches all contexts, i.e. clears the slave list from the
1136context. Anonymous (C<%name>) contexts have no attached slaves by default, 1212context. Anonymous (C<%name>) contexts have no attached slaves by default,
1137but package contexts have the parent context as slave by default. 1213but package contexts have the parent context as slave by default.
1138 1214
1139Example: log messages from My::Module to a file, do not send them to the 1215Example: log messages from My::Module to a file, do not send them to the
1140default log collector. 1216default log collector.
1171 1247
1172 my $pkg = sub { 1248 my $pkg = sub {
1173 $_[0] eq "log" ? $LOG 1249 $_[0] eq "log" ? $LOG
1174 : $_[0] eq "filter" ? $FILTER 1250 : $_[0] eq "filter" ? $FILTER
1175 : $_[0] eq "collect" ? $COLLECT 1251 : $_[0] eq "collect" ? $COLLECT
1176 : $_[0] =~ /^%(.+)$/ ? ($anon{$1} ||= ctx undef) 1252 : $_[0] =~ /^%(.+)$/ ? ($anon{$1} ||= do { my $ctx = ctx undef; $ctx->[0] = $_[0]; $ctx })
1177 : $_[0] =~ /^(.*?)(?:::)?$/ ? ctx "$1" # egad :/ 1253 : $_[0] =~ /^(.*?)(?:::)?$/ ? ctx "$1" # egad :/
1178 : die # never reached? 1254 : die # never reached?
1179 }; 1255 };
1180 1256
1181 /\G[[:space:]]+/gc; # skip initial whitespace 1257 /\G[[:space:]]+/gc; # skip initial whitespace
1187 while (/\G((?:[^,:[:space:]]+|::|\\.)+)/gc) { 1263 while (/\G((?:[^,:[:space:]]+|::|\\.)+)/gc) {
1188 for ("$1") { 1264 for ("$1") {
1189 if ($_ eq "stderr" ) { $ctx->log_to_warn; 1265 if ($_ eq "stderr" ) { $ctx->log_to_warn;
1190 } elsif (/^file=(.+)/ ) { $ctx->log_to_file ("$1"); 1266 } elsif (/^file=(.+)/ ) { $ctx->log_to_file ("$1");
1191 } elsif (/^path=(.+)/ ) { $ctx->log_to_path ("$1"); 1267 } elsif (/^path=(.+)/ ) { $ctx->log_to_path ("$1");
1192 } elsif (/syslog(?:=(.*))?/ ) { require Sys::Syslog; $ctx->log_to_syslog ($1); 1268 } elsif (/^syslog(?:=(.*))?/ ) { require Sys::Syslog; $ctx->log_to_syslog ("$1");
1193 } elsif ($_ eq "nolog" ) { $ctx->log_cb (undef); 1269 } elsif ($_ eq "nolog" ) { $ctx->log_cb (undef);
1270 } elsif (/^cap=(.+)/ ) { $ctx->cap ("$1");
1194 } elsif (/^\+(.+)$/ ) { $ctx->attach ($pkg->("$1")); 1271 } elsif (/^\+(.+)$/ ) { $ctx->attach ($pkg->("$1"));
1195 } elsif ($_ eq "+" ) { $ctx->slaves; 1272 } elsif ($_ eq "+" ) { $ctx->slaves;
1196 } elsif ($_ eq "off" or $_ eq "0") { $ctx->level (0); 1273 } elsif ($_ eq "off" or $_ eq "0") { $ctx->level (0);
1197 } elsif ($_ eq "all" ) { $ctx->level ("all"); 1274 } elsif ($_ eq "all" ) { $ctx->level ("all");
1198 } elsif ($_ eq "level" ) { $ctx->level ("all"); $level = "level"; 1275 } elsif ($_ eq "level" ) { $ctx->level ("all"); $level = "level";
1266 1343
1267 PERL_ANYEVENT_LOG=%filelogger=file=/some/path:collect=+%filelogger 1344 PERL_ANYEVENT_LOG=%filelogger=file=/some/path:collect=+%filelogger
1268 1345
1269In both cases, messages are still written to STDERR. 1346In both cases, messages are still written to STDERR.
1270 1347
1348=item Additionally log all messages with C<warn> and higher priority to
1349C<syslog>, but cap at C<error>.
1350
1351This logs all messages to the default log target, but also logs messages
1352with priority C<warn> or higher (and not filtered otherwise) to syslog
1353facility C<user>. Messages with priority higher than C<error> will be
1354logged with level C<error>.
1355
1356 $AnyEvent::Log::LOG->attach (
1357 new AnyEvent::Log::Ctx
1358 level => "warn",
1359 cap => "error",
1360 syslog => "user",
1361 );
1362
1363 PERL_ANYEVENT_LOG=log=+%syslog:%syslog=warn,cap=error,syslog
1364
1271=item Write trace messages (only) from L<AnyEvent::Debug> to the default logging target(s). 1365=item Write trace messages (only) from L<AnyEvent::Debug> to the default logging target(s).
1272 1366
1273Attach the C<$AnyEvent::Log::LOG> context to the C<AnyEvent::Debug> 1367Attach the C<$AnyEvent::Log::LOG> context to the C<AnyEvent::Debug>
1274context - this simply circumvents the global filtering for trace messages. 1368context - this simply circumvents the global filtering for trace messages.
1275 1369

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines