… | |
… | |
967 | filter=debug:log=+%warnings:%warnings=warn,syslog=LOG_LOCAL0 |
967 | filter=debug:log=+%warnings:%warnings=warn,syslog=LOG_LOCAL0 |
968 | |
968 | |
969 | # log trace messages (only) from AnyEvent::Debug to file |
969 | # log trace messages (only) from AnyEvent::Debug to file |
970 | AnyEvent::Debug=+%trace:%trace=only,trace,file=/tmp/tracelog |
970 | AnyEvent::Debug=+%trace:%trace=only,trace,file=/tmp/tracelog |
971 | |
971 | |
|
|
972 | Since whitespace (which includes newlines) is allowed, it is fine to |
|
|
973 | specify multiple lines in C<PERL_ANYEVENT_LOG>, e.g.: |
|
|
974 | |
|
|
975 | PERL_ANYEVENT_LOG=" |
|
|
976 | filter=warn |
|
|
977 | AnyEvent::Debug=+%trace |
|
|
978 | %trace=only,trace,+log |
|
|
979 | " myprog |
|
|
980 | |
972 | A context name in the log specification can be any of the following: |
981 | A context name in the log specification can be any of the following: |
973 | |
982 | |
974 | =over 4 |
983 | =over 4 |
975 | |
984 | |
976 | =item C<collect>, C<filter>, C<log> |
985 | =item C<collect>, C<filter>, C<log> |
… | |
… | |
1093 | |
1102 | |
1094 | for (my $spec = $ENV{PERL_ANYEVENT_LOG}) { |
1103 | for (my $spec = $ENV{PERL_ANYEVENT_LOG}) { |
1095 | my %anon; |
1104 | my %anon; |
1096 | |
1105 | |
1097 | my $pkg = sub { |
1106 | my $pkg = sub { |
1098 | $_[0] eq "log" ? $LOG |
1107 | $_[0] eq "log" ? $LOG |
1099 | : $_[0] eq "filter" ? $FILTER |
1108 | : $_[0] eq "filter" ? $FILTER |
1100 | : $_[0] eq "collect" ? $COLLECT |
1109 | : $_[0] eq "collect" ? $COLLECT |
1101 | : $_[0] =~ /^%(.+)$/ && $anon{$1} ||= ctx undef |
1110 | : $_[0] =~ /^%(.+)$/ ? ($anon{$1} ||= ctx undef) |
1102 | : $_[0] =~ /^(.*?)(?:::)?$/ && ctx "$1" # egad :/ |
1111 | : $_[0] =~ /^(.*?)(?:::)?$/ ? ctx "$1" # egad :/ |
|
|
1112 | : die # never reached? |
1103 | }; |
1113 | }; |
1104 | |
1114 | |
|
|
1115 | /\G[[:space:]]+/gc; # skip initial whitespace |
|
|
1116 | |
1105 | while (/\G((?:[^:=]+|::|\\.)+)=/gc) { |
1117 | while (/\G((?:[^:=[:space:]]+|::|\\.)+)=/gc) { |
1106 | my $ctx = $pkg->($1); |
1118 | my $ctx = $pkg->($1); |
1107 | my $level = "level"; |
1119 | my $level = "level"; |
1108 | |
1120 | |
1109 | while (/\G((?:[^,:[:space:]]+|::|\\.)+)/gc) { |
1121 | while (/\G((?:[^,:[:space:]]+|::|\\.)+)/gc) { |
1110 | for ("$1") { |
1122 | for ("$1") { |
… | |
… | |
1127 | } |
1139 | } |
1128 | |
1140 | |
1129 | /\G,/gc or last; |
1141 | /\G,/gc or last; |
1130 | } |
1142 | } |
1131 | |
1143 | |
1132 | /\G[:[:space:]]/gc or last; |
1144 | /\G[:[:space:]]+/gc or last; |
1133 | } |
1145 | } |
|
|
1146 | |
|
|
1147 | /\G[[:space:]]+/gc; # skip trailing whitespace |
1134 | |
1148 | |
1135 | if (/\G(.+)/g) { |
1149 | if (/\G(.+)/g) { |
1136 | die "PERL_ANYEVENT_LOG ($spec): parse error at '$1'\n"; |
1150 | die "PERL_ANYEVENT_LOG ($spec): parse error at '$1'\n"; |
1137 | } |
1151 | } |
1138 | } |
1152 | } |
1139 | |
1153 | |
1140 | 1; |
1154 | 1; |
1141 | |
1155 | |
1142 | =head1 EXAMPLES |
1156 | =head1 EXAMPLES |
1143 | |
1157 | |
1144 | This section shows some common configurations. |
1158 | This section shows some common configurations, both as code, and as |
|
|
1159 | C<PERL_ANYEVENT_LOG> string. |
1145 | |
1160 | |
1146 | =over 4 |
1161 | =over 4 |
1147 | |
1162 | |
1148 | =item Setting the global logging level. |
1163 | =item Setting the global logging level. |
1149 | |
1164 | |
1150 | Either put PERL_ANYEVENT_VERBOSE=<number> into your environment before |
1165 | Either put C<PERL_ANYEVENT_VERBOSE=><number> into your environment before |
1151 | running your program, or modify the log level of the root context: |
1166 | running your program, use C<PERL_ANYEVENT_LOG> or modify the log level of |
|
|
1167 | the root context at runtime: |
1152 | |
1168 | |
1153 | PERL_ANYEVENT_VERBOSE=5 ./myprog |
1169 | PERL_ANYEVENT_VERBOSE=5 ./myprog |
1154 | |
1170 | |
|
|
1171 | PERL_ANYEVENT_LOG=log=warn |
|
|
1172 | |
1155 | $AnyEvent::Log::FILTER->level ("warn"); |
1173 | $AnyEvent::Log::FILTER->level ("warn"); |
1156 | |
1174 | |
1157 | =item Append all messages to a file instead of sending them to STDERR. |
1175 | =item Append all messages to a file instead of sending them to STDERR. |
1158 | |
1176 | |
1159 | This is affected by the global logging level. |
1177 | This is affected by the global logging level. |
1160 | |
1178 | |
1161 | $AnyEvent::Log::LOG->log_to_file ($path); (sub { |
1179 | $AnyEvent::Log::LOG->log_to_file ($path); |
|
|
1180 | |
|
|
1181 | PERL_ANYEVENT_LOG=log=file=/some/path |
1162 | |
1182 | |
1163 | =item Write all messages with priority C<error> and higher to a file. |
1183 | =item Write all messages with priority C<error> and higher to a file. |
1164 | |
1184 | |
1165 | This writes them only when the global logging level allows it, because |
1185 | 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 |
1186 | it is attached to the default context which is invoked I<after> global |
1167 | filtering. |
1187 | filtering. |
1168 | |
1188 | |
1169 | $AnyEvent::Log::FILTER->attach |
1189 | $AnyEvent::Log::FILTER->attach |
1170 | new AnyEvent::Log::Ctx log_to_file => $path); |
1190 | new AnyEvent::Log::Ctx log_to_file => $path); |
1171 | |
1191 | |
|
|
1192 | PERL_ANYEVENT_LOG=filter=+%filelogger:%filelogger=file=/some/path |
|
|
1193 | |
1172 | This writes them regardless of the global logging level, because it is |
1194 | This writes them regardless of the global logging level, because it is |
1173 | attached to the toplevel context, which receives all messages I<before> |
1195 | attached to the toplevel context, which receives all messages I<before> |
1174 | the global filtering. |
1196 | the global filtering. |
1175 | |
1197 | |
1176 | $AnyEvent::Log::COLLECT->attach ( |
1198 | $AnyEvent::Log::COLLECT->attach ( |
1177 | new AnyEvent::Log::Ctx log_to_file => $path); |
1199 | new AnyEvent::Log::Ctx log_to_file => $path); |
1178 | |
1200 | |
|
|
1201 | PERL_ANYEVENT_LOG=%filelogger=file=/some/path:collect=+%filelogger |
|
|
1202 | |
1179 | In both cases, messages are still written to STDERR. |
1203 | In both cases, messages are still written to STDERR. |
1180 | |
1204 | |
1181 | =item Write trace messages (only) from L<AnyEvent::Debug> to the default logging target(s). |
1205 | =item Write trace messages (only) from L<AnyEvent::Debug> to the default logging target(s). |
1182 | |
1206 | |
1183 | Attach the C<$AnyEvent::Log::LOG> context to the C<AnyEvent::Debug> |
1207 | Attach the C<$AnyEvent::Log::LOG> context to the C<AnyEvent::Debug> |
1184 | context - this simply circumvents the global filtering for trace messages. |
1208 | context - this simply circumvents the global filtering for trace messages. |
1185 | |
1209 | |
1186 | my $debug = AnyEvent::Debug->AnyEvent::Log::ctx; |
1210 | my $debug = AnyEvent::Debug->AnyEvent::Log::ctx; |
1187 | $debug->attach ($AnyEvent::Log::LOG); |
1211 | $debug->attach ($AnyEvent::Log::LOG); |
|
|
1212 | |
|
|
1213 | PERL_ANYEVENT_LOG=AnyEvent::Debug=+log |
1188 | |
1214 | |
1189 | This of course works for any package, not just L<AnyEvent::Debug>, but |
1215 | 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 |
1216 | assumes the log level for AnyEvent::Debug hasn't been changed from the |
1191 | default. |
1217 | default. |
1192 | |
1218 | |
… | |
… | |
1196 | |
1222 | |
1197 | Marc Lehmann <schmorp@schmorp.de> |
1223 | Marc Lehmann <schmorp@schmorp.de> |
1198 | http://home.schmorp.de/ |
1224 | http://home.schmorp.de/ |
1199 | |
1225 | |
1200 | =cut |
1226 | =cut |
|
|
1227 | |