… | |
… | |
56 | The design goal behind this module was to keep it simple (and small), |
56 | The design goal behind this module was to keep it simple (and small), |
57 | but make it powerful enough to be potentially useful for any module, and |
57 | but make it powerful enough to be potentially useful for any module, and |
58 | extensive enough for the most common tasks, such as logging to multiple |
58 | extensive enough for the most common tasks, such as logging to multiple |
59 | targets, or being able to log into a database. |
59 | targets, or being able to log into a database. |
60 | |
60 | |
61 | The amount of documentation might indicate otherwise, but the module is |
61 | The amount of documentation might indicate otherwise, but the runtime part |
62 | still just below 300 lines of code. |
62 | of the module is still just below 300 lines of code. |
63 | |
63 | |
64 | =head1 LOGGING LEVELS |
64 | =head1 LOGGING LEVELS |
65 | |
65 | |
66 | Logging levels in this module range from C<1> (highest priority) to C<9> |
66 | Logging levels in this module range from C<1> (highest priority) to C<9> |
67 | (lowest priority). Note that the lowest numerical value is the highest |
67 | (lowest priority). Note that the lowest numerical value is the highest |
… | |
… | |
249 | # now get raw message, unless we have it already |
249 | # now get raw message, unless we have it already |
250 | unless ($now) { |
250 | unless ($now) { |
251 | $format = $format->() if ref $format; |
251 | $format = $format->() if ref $format; |
252 | $format = sprintf $format, @args if @args; |
252 | $format = sprintf $format, @args if @args; |
253 | $format =~ s/\n$//; |
253 | $format =~ s/\n$//; |
254 | $now = AE::now; |
254 | $now = now; |
255 | }; |
255 | }; |
256 | |
256 | |
257 | # format msg |
257 | # format msg |
258 | my $str = $ctx->[4] |
258 | my $str = $ctx->[4] |
259 | ? $ctx->[4]($now, $_[0], $level, $format) |
259 | ? $ctx->[4]($now, $_[0], $level, $format) |
… | |
… | |
1012 | Configures the context to log to a file with the given path. Works like |
1012 | Configures the context to log to a file with the given path. Works like |
1013 | C<log_to_path>. |
1013 | C<log_to_path>. |
1014 | |
1014 | |
1015 | =item C<syslog> or C<syslog=>I<expr> |
1015 | =item C<syslog> or C<syslog=>I<expr> |
1016 | |
1016 | |
1017 | Configured the context to log to syslog. If I<expr> is given, then it is |
1017 | Configures the context to log to syslog. If I<expr> is given, then it is |
1018 | evaluated in the L<Sys::Syslog> package, so you could use: |
1018 | evaluated in the L<Sys::Syslog> package, so you could use: |
1019 | |
1019 | |
1020 | log=syslog=LOG_LOCAL0 |
1020 | log=syslog=LOG_LOCAL0 |
1021 | |
1021 | |
1022 | =item C<nolog> |
1022 | =item C<nolog> |
… | |
… | |
1064 | filter=warn |
1064 | filter=warn |
1065 | |
1065 | |
1066 | # or, more verbose |
1066 | # or, more verbose |
1067 | filter=only,level,warn |
1067 | filter=only,level,warn |
1068 | |
1068 | |
1069 | =item C<1>..C<9>, a logging level name (C<error>, C<debug> etc.) |
1069 | =item C<1>..C<9> or a logging level name (C<error>, C<debug> etc.) |
1070 | |
1070 | |
1071 | A numeric loglevel or the name of a loglevel will be interpreted according |
1071 | A numeric loglevel or the name of a loglevel will be interpreted according |
1072 | to the most recent C<only>, C<except> or C<level> directive. By default, |
1072 | to the most recent C<only>, C<except> or C<level> directive. By default, |
1073 | specifying a logging level enables that and any higher priority messages. |
1073 | specifying a logging level enables that and any higher priority messages. |
1074 | |
1074 | |
1075 | =item C<+>I<context> |
1075 | =item C<+>I<context> |
1076 | |
1076 | |
1077 | Adds/attaches the named context as slave to the context. |
1077 | Attaches the named context as slave to the context. |
1078 | |
1078 | |
1079 | =item C<+> |
1079 | =item C<+> |
1080 | |
1080 | |
1081 | A line C<+> clears the slave list form the context. Anonymous (C<%name>) |
1081 | A line C<+> detaches all contexts, i.e. clears the slave list from the |
1082 | contexts have no slaves by default, but package contexts have the parent |
1082 | context. Anonymous (C<%name>) contexts have no attached slaves by default, |
1083 | context as slave by default. |
1083 | but package contexts have the parent context as slave by default. |
1084 | |
1084 | |
1085 | Example: log messages from My::Module to a file, do not send them to the |
1085 | Example: log messages from My::Module to a file, do not send them to the |
1086 | default log collector. |
1086 | default log collector. |
1087 | |
1087 | |
1088 | My::Module=+,file=/tmp/mymodulelog |
1088 | My::Module=+,file=/tmp/mymodulelog |
1089 | |
1089 | |
1090 | =back |
1090 | =back |
1091 | |
1091 | |
1092 | Any character can be escaped by prefixing it with a C<\> (backslash), as |
1092 | Any character can be escaped by prefixing it with a C<\> (backslash), as |
1093 | usual, so to log to a file containing a comma, colon, backslash and space in the |
1093 | usual, so to log to a file containing a comma, colon, backslash and some |
1094 | filename, you would do this: |
1094 | spaces in the filename, you would do this: |
1095 | |
1095 | |
1096 | PERL_ANYEVENT_LOG='log=file=/some\ \:file\ with\,\ \\-escapes' |
1096 | PERL_ANYEVENT_LOG='log=file=/some\ \:file\ with\,\ \\-escapes' |
1097 | |
1097 | |
1098 | Since whitespace (which includes newlines) is allowed, it is fine to |
1098 | Since whitespace (which includes newlines) is allowed, it is fine to |
1099 | specify multiple lines in C<PERL_ANYEVENT_LOG>, e.g.: |
1099 | specify multiple lines in C<PERL_ANYEVENT_LOG>, e.g.: |