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.27 by root, Wed Aug 24 23:59:10 2011 UTC vs.
Revision 1.29 by root, Thu Aug 25 00:14:32 2011 UTC

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
972Since whitespace (which includes newlines) is allowed, it is fine to
973specify 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
972A context name in the log specification can be any of the following: 981A 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
1094for (my $spec = $ENV{PERL_ANYEVENT_LOG}) { 1103for (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
11401; 11541;
1141 1155
1142=head1 EXAMPLES 1156=head1 EXAMPLES
1143 1157
1144This section shows some common configurations. 1158This section shows some common configurations, both as code, and as
1159C<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
1150Either put PERL_ANYEVENT_VERBOSE=<number> into your environment before 1165Either put C<PERL_ANYEVENT_VERBOSE=><number> into your environment before
1151running your program, or modify the log level of the root context: 1166running your program, use C<PERL_ANYEVENT_LOG> or modify the log level of
1167the 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
1159This is affected by the global logging level. 1177This 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
1165This writes them only when the global logging level allows it, because 1185This writes them only when the global logging level allows it, because
1166it is attached to the default context which is invoked I<after> global 1186it is attached to the default context which is invoked I<after> global
1167filtering. 1187filtering.
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
1172This writes them regardless of the global logging level, because it is 1194This writes them regardless of the global logging level, because it is
1173attached to the toplevel context, which receives all messages I<before> 1195attached to the toplevel context, which receives all messages I<before>
1174the global filtering. 1196the 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
1179In both cases, messages are still written to STDERR. 1203In 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
1183Attach the C<$AnyEvent::Log::LOG> context to the C<AnyEvent::Debug> 1207Attach the C<$AnyEvent::Log::LOG> context to the C<AnyEvent::Debug>
1184context - this simply circumvents the global filtering for trace messages. 1208context - 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
1189This of course works for any package, not just L<AnyEvent::Debug>, but 1215This of course works for any package, not just L<AnyEvent::Debug>, but
1190assumes the log level for AnyEvent::Debug hasn't been changed from the 1216assumes the log level for AnyEvent::Debug hasn't been changed from the
1191default. 1217default.
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines