… | |
… | |
1139 | |
1139 | |
1140 | 1; |
1140 | 1; |
1141 | |
1141 | |
1142 | =head1 EXAMPLES |
1142 | =head1 EXAMPLES |
1143 | |
1143 | |
1144 | This section shows some common configurations. |
1144 | This section shows some common configurations, both as code, and as |
|
|
1145 | C<PERL_ANYEVENT_LOG> string. |
1145 | |
1146 | |
1146 | =over 4 |
1147 | =over 4 |
1147 | |
1148 | |
1148 | =item Setting the global logging level. |
1149 | =item Setting the global logging level. |
1149 | |
1150 | |
1150 | Either put PERL_ANYEVENT_VERBOSE=<number> into your environment before |
1151 | Either put C<PERL_ANYEVENT_VERBOSE=><number> into your environment before |
1151 | running your program, or modify the log level of the root context: |
1152 | running your program, use C<PERL_ANYEVENT_LOG> or modify the log level of |
|
|
1153 | the root context at runtime: |
1152 | |
1154 | |
1153 | PERL_ANYEVENT_VERBOSE=5 ./myprog |
1155 | PERL_ANYEVENT_VERBOSE=5 ./myprog |
1154 | |
1156 | |
|
|
1157 | PERL_ANYEVENT_LOG=log=warn |
|
|
1158 | |
1155 | $AnyEvent::Log::FILTER->level ("warn"); |
1159 | $AnyEvent::Log::FILTER->level ("warn"); |
1156 | |
1160 | |
1157 | =item Append all messages to a file instead of sending them to STDERR. |
1161 | =item Append all messages to a file instead of sending them to STDERR. |
1158 | |
1162 | |
1159 | This is affected by the global logging level. |
1163 | This is affected by the global logging level. |
1160 | |
1164 | |
1161 | $AnyEvent::Log::LOG->log_to_file ($path); (sub { |
1165 | $AnyEvent::Log::LOG->log_to_file ($path); |
|
|
1166 | |
|
|
1167 | PERL_ANYEVENT_LOG=log=file=/some/path |
1162 | |
1168 | |
1163 | =item Write all messages with priority C<error> and higher to a file. |
1169 | =item Write all messages with priority C<error> and higher to a file. |
1164 | |
1170 | |
1165 | This writes them only when the global logging level allows it, because |
1171 | This writes them only when the global logging level allows it, because |
1166 | it is attached to the default context which is invoked I<after> global |
1172 | it is attached to the default context which is invoked I<after> global |
1167 | filtering. |
1173 | filtering. |
1168 | |
1174 | |
1169 | $AnyEvent::Log::FILTER->attach |
1175 | $AnyEvent::Log::FILTER->attach |
1170 | new AnyEvent::Log::Ctx log_to_file => $path); |
1176 | new AnyEvent::Log::Ctx log_to_file => $path); |
1171 | |
1177 | |
|
|
1178 | PERL_ANYEVENT_LOG=filter=+%filelogger:%filelogger=file=/some/path |
|
|
1179 | |
1172 | This writes them regardless of the global logging level, because it is |
1180 | This writes them regardless of the global logging level, because it is |
1173 | attached to the toplevel context, which receives all messages I<before> |
1181 | attached to the toplevel context, which receives all messages I<before> |
1174 | the global filtering. |
1182 | the global filtering. |
1175 | |
1183 | |
1176 | $AnyEvent::Log::COLLECT->attach ( |
1184 | $AnyEvent::Log::COLLECT->attach ( |
1177 | new AnyEvent::Log::Ctx log_to_file => $path); |
1185 | new AnyEvent::Log::Ctx log_to_file => $path); |
1178 | |
1186 | |
|
|
1187 | PERL_ANYEVENT_LOG=%filelogger=file=/some/path:collect=+%filelogger |
|
|
1188 | |
1179 | In both cases, messages are still written to STDERR. |
1189 | In both cases, messages are still written to STDERR. |
1180 | |
1190 | |
1181 | =item Write trace messages (only) from L<AnyEvent::Debug> to the default logging target(s). |
1191 | =item Write trace messages (only) from L<AnyEvent::Debug> to the default logging target(s). |
1182 | |
1192 | |
1183 | Attach the C<$AnyEvent::Log::LOG> context to the C<AnyEvent::Debug> |
1193 | Attach the C<$AnyEvent::Log::LOG> context to the C<AnyEvent::Debug> |
1184 | context - this simply circumvents the global filtering for trace messages. |
1194 | context - this simply circumvents the global filtering for trace messages. |
1185 | |
1195 | |
1186 | my $debug = AnyEvent::Debug->AnyEvent::Log::ctx; |
1196 | my $debug = AnyEvent::Debug->AnyEvent::Log::ctx; |
1187 | $debug->attach ($AnyEvent::Log::LOG); |
1197 | $debug->attach ($AnyEvent::Log::LOG); |
|
|
1198 | |
|
|
1199 | PERL_ANYEVENT_LOG=AnyEvent::Debug=+log |
1188 | |
1200 | |
1189 | This of course works for any package, not just L<AnyEvent::Debug>, but |
1201 | This of course works for any package, not just L<AnyEvent::Debug>, but |
1190 | assumes the log level for AnyEvent::Debug hasn't been changed from the |
1202 | assumes the log level for AnyEvent::Debug hasn't been changed from the |
1191 | default. |
1203 | default. |
1192 | |
1204 | |
… | |
… | |
1196 | |
1208 | |
1197 | Marc Lehmann <schmorp@schmorp.de> |
1209 | Marc Lehmann <schmorp@schmorp.de> |
1198 | http://home.schmorp.de/ |
1210 | http://home.schmorp.de/ |
1199 | |
1211 | |
1200 | =cut |
1212 | =cut |
|
|
1213 | |