… | |
… | |
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) |
… | |
… | |
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 |
|
|
1093 | usual, so to log to a file containing a comma, colon, backslash and space in the |
|
|
1094 | filename, you would do this: |
|
|
1095 | |
|
|
1096 | PERL_ANYEVENT_LOG='log=file=/some\ \:file\ with\,\ \\-escapes' |
|
|
1097 | |
|
|
1098 | Since whitespace (which includes newlines) is allowed, it is fine to |
|
|
1099 | specify multiple lines in C<PERL_ANYEVENT_LOG>, e.g.: |
|
|
1100 | |
|
|
1101 | PERL_ANYEVENT_LOG=" |
|
|
1102 | filter=warn |
|
|
1103 | AnyEvent::Debug=+%trace |
|
|
1104 | %trace=only,trace,+log |
|
|
1105 | " myprog |
|
|
1106 | |
|
|
1107 | Also, in the unlikely case when you want to concatenate specifications, |
|
|
1108 | use whitespace as separator, as C<::> will be interpreted as part of a |
|
|
1109 | module name, an empty spec with two separators: |
|
|
1110 | |
|
|
1111 | PERL_ANYEVENT_LOG="$PERL_ANYEVENT_LOG MyMod=debug" |
|
|
1112 | |
1092 | =cut |
1113 | =cut |
1093 | |
1114 | |
1094 | for (my $spec = $ENV{PERL_ANYEVENT_LOG}) { |
1115 | for (my $spec = $ENV{PERL_ANYEVENT_LOG}) { |
1095 | my %anon; |
1116 | my %anon; |
1096 | |
1117 | |
1097 | my $pkg = sub { |
1118 | my $pkg = sub { |
1098 | $_[0] eq "log" ? $LOG |
1119 | $_[0] eq "log" ? $LOG |
1099 | : $_[0] eq "filter" ? $FILTER |
1120 | : $_[0] eq "filter" ? $FILTER |
1100 | : $_[0] eq "collect" ? $COLLECT |
1121 | : $_[0] eq "collect" ? $COLLECT |
1101 | : $_[0] =~ /^%(.+)$/ && $anon{$1} ||= ctx undef |
1122 | : $_[0] =~ /^%(.+)$/ ? ($anon{$1} ||= ctx undef) |
1102 | : $_[0] =~ /^(.*?)(?:::)?$/ && ctx "$1" # egad :/ |
1123 | : $_[0] =~ /^(.*?)(?:::)?$/ ? ctx "$1" # egad :/ |
|
|
1124 | : die # never reached? |
1103 | }; |
1125 | }; |
1104 | |
1126 | |
|
|
1127 | /\G[[:space:]]+/gc; # skip initial whitespace |
|
|
1128 | |
1105 | while (/\G((?:[^:=]+|::|\\.)+)=/gc) { |
1129 | while (/\G((?:[^:=[:space:]]+|::|\\.)+)=/gc) { |
1106 | my $ctx = $pkg->($1); |
1130 | my $ctx = $pkg->($1); |
1107 | my $level = "level"; |
1131 | my $level = "level"; |
1108 | |
1132 | |
1109 | while (/\G((?:[^,:[:space:]]+|::|\\.)+)/gc) { |
1133 | while (/\G((?:[^,:[:space:]]+|::|\\.)+)/gc) { |
1110 | for ("$1") { |
1134 | for ("$1") { |
… | |
… | |
1127 | } |
1151 | } |
1128 | |
1152 | |
1129 | /\G,/gc or last; |
1153 | /\G,/gc or last; |
1130 | } |
1154 | } |
1131 | |
1155 | |
1132 | /\G[:[:space:]]/gc or last; |
1156 | /\G[:[:space:]]+/gc or last; |
1133 | } |
1157 | } |
|
|
1158 | |
|
|
1159 | /\G[[:space:]]+/gc; # skip trailing whitespace |
1134 | |
1160 | |
1135 | if (/\G(.+)/g) { |
1161 | if (/\G(.+)/g) { |
1136 | die "PERL_ANYEVENT_LOG ($spec): parse error at '$1'\n"; |
1162 | die "PERL_ANYEVENT_LOG ($spec): parse error at '$1'\n"; |
1137 | } |
1163 | } |
1138 | } |
1164 | } |