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.39 by root, Fri Aug 26 00:37:26 2011 UTC vs.
Revision 1.40 by root, Fri Aug 26 16:18:01 2011 UTC

32 32
33 # send all critical and higher priority messages to syslog, 33 # send all critical and higher priority messages to syslog,
34 # regardless of (most) other settings 34 # regardless of (most) other settings
35 $AnyEvent::Log::COLLECT->attach (new AnyEvent::Log::Ctx 35 $AnyEvent::Log::COLLECT->attach (new AnyEvent::Log::Ctx
36 level => "critical", 36 level => "critical",
37 log_to_syslog => 0, 37 log_to_syslog => "user",
38 ); 38 );
39 39
40=head1 DESCRIPTION 40=head1 DESCRIPTION
41 41
42This module implements a relatively simple "logging framework". It doesn't 42This module implements a relatively simple "logging framework". It doesn't
864 864
865Needless(?) to say, if you do not want to be bitten by some evil person 865Needless(?) to say, if you do not want to be bitten by some evil person
866calling C<chdir>, the path should be absolute. Doesn't help with 866calling C<chdir>, the path should be absolute. Doesn't help with
867C<chroot>, but hey... 867C<chroot>, but hey...
868 868
869=item $ctx->log_to_syslog ([$log_flags]) 869=item $ctx->log_to_syslog ([$facility])
870 870
871Logs all messages via L<Sys::Syslog>, mapping C<trace> to C<debug> and all 871Logs all messages via L<Sys::Syslog>, mapping C<trace> to C<debug> and
872the others in the obvious way. If specified, then the C<$log_flags> are 872all the others in the obvious way. If specified, then the C<$facility> is
873simply or'ed onto the priority argument and can contain any C<LOG_xxx> 873used as the facility (C<user>, C<auth>, C<local0> and so on). The default
874flags valid for Sys::Syslog::syslog, except for the priority levels. 874facility is C<user>.
875 875
876Note that this function also sets a C<fmt_cb> - the logging part requires 876Note that this function also sets a C<fmt_cb> - the logging part requires
877an array reference with [$level, $str] as input. 877an array reference with [$level, $str] as input.
878 878
879=cut 879=cut
922 0 922 0
923 }); 923 });
924} 924}
925 925
926sub log_to_syslog { 926sub log_to_syslog {
927 my ($ctx, $flags) = @_; 927 my ($ctx, $facility) = @_;
928 928
929 require Sys::Syslog; 929 require Sys::Syslog;
930 930
931 $ctx->fmt_cb (sub { 931 $ctx->fmt_cb (sub {
932 my $str = $_[3]; 932 my $str = $_[3];
933 $str =~ s/\n(?=.)/\n+ /g; 933 $str =~ s/\n(?=.)/\n+ /g;
934 934
935 [$_[2], "($_[1][0]) $str"] 935 [$_[2], "($_[1][0]) $str"]
936 }); 936 });
937 937
938 $facility ||= "user";
939
938 $ctx->log_cb (sub { 940 $ctx->log_cb (sub {
939 my $lvl = $_[0][0] < 9 ? $_[0][0] : 8; 941 my $lvl = $_[0][0] < 9 ? $_[0][0] : 8;
940 942
941 Sys::Syslog::syslog ($flags | ($lvl - 1), $_) 943 Sys::Syslog::syslog ("$facility|" . ($lvl - 1), $_)
942 for split /\n/, $_[0][1]; 944 for split /\n/, $_[0][1];
943 945
944 0 946 0
945 }); 947 });
946} 948}
1163 while (/\G((?:[^,:[:space:]]+|::|\\.)+)/gc) { 1165 while (/\G((?:[^,:[:space:]]+|::|\\.)+)/gc) {
1164 for ("$1") { 1166 for ("$1") {
1165 if ($_ eq "stderr" ) { $ctx->log_to_warn; 1167 if ($_ eq "stderr" ) { $ctx->log_to_warn;
1166 } elsif (/^file=(.+)/ ) { $ctx->log_to_file ("$1"); 1168 } elsif (/^file=(.+)/ ) { $ctx->log_to_file ("$1");
1167 } elsif (/^path=(.+)/ ) { $ctx->log_to_path ("$1"); 1169 } elsif (/^path=(.+)/ ) { $ctx->log_to_path ("$1");
1168 } elsif (/syslog(?:=(.*))?/ ) { require Sys::Syslog; $ctx->log_to_syslog (eval "package Sys::Syslog; $1"); 1170 } elsif (/syslog(?:=(.*))?/ ) { require Sys::Syslog; $ctx->log_to_syslog ($1);
1169 } elsif ($_ eq "nolog" ) { $ctx->log_cb (undef); 1171 } elsif ($_ eq "nolog" ) { $ctx->log_cb (undef);
1170 } elsif (/^\+(.+)$/ ) { $ctx->attach ($pkg->("$1")); 1172 } elsif (/^\+(.+)$/ ) { $ctx->attach ($pkg->("$1"));
1171 } elsif ($_ eq "+" ) { $ctx->slaves; 1173 } elsif ($_ eq "+" ) { $ctx->slaves;
1172 } elsif ($_ eq "off" or $_ eq "0") { $ctx->level (0); 1174 } elsif ($_ eq "off" or $_ eq "0") { $ctx->level (0);
1173 } elsif ($_ eq "all" ) { $ctx->level ("all"); 1175 } elsif ($_ eq "all" ) { $ctx->level ("all");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines