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.32 by root, Thu Aug 25 04:56:16 2011 UTC vs.
Revision 1.37 by root, Thu Aug 25 06:34:11 2011 UTC

49will be logged, unless you set C<PERL_ANYEVENT_VERBOSE> to a higher number 49will be logged, unless you set C<PERL_ANYEVENT_VERBOSE> to a higher number
50before starting your program, or change the logging level at runtime with 50before starting your program, or change the logging level at runtime with
51something like: 51something like:
52 52
53 use AnyEvent::Log; 53 use AnyEvent::Log;
54 AnyEvent::Log::FILTER->level ("info"); 54 $AnyEvent::Log::FILTER->level ("info");
55 55
56The design goal behind this module was to keep it simple (and small), 56The design goal behind this module was to keep it simple (and small),
57but make it powerful enough to be potentially useful for any module, and 57but make it powerful enough to be potentially useful for any module, and
58extensive enough for the most common tasks, such as logging to multiple 58extensive enough for the most common tasks, such as logging to multiple
59targets, or being able to log into a database. 59targets, or being able to log into a database.
60 60
61The module is also usable before AnyEvent itself is initialised, in which
62case some of the functionality might be reduced.
63
61The amount of documentation might indicate otherwise, but the module is 64The amount of documentation might indicate otherwise, but the runtime part
62still just below 300 lines of code. 65of the module is still just below 300 lines of code.
63 66
64=head1 LOGGING LEVELS 67=head1 LOGGING LEVELS
65 68
66Logging levels in this module range from C<1> (highest priority) to C<9> 69Logging levels in this module range from C<1> (highest priority) to C<9>
67(lowest priority). Note that the lowest numerical value is the highest 70(lowest priority). Note that the lowest numerical value is the highest
108 111
109use Carp (); 112use Carp ();
110use POSIX (); 113use POSIX ();
111 114
112use AnyEvent (); BEGIN { AnyEvent::common_sense } 115use AnyEvent (); BEGIN { AnyEvent::common_sense }
113use AnyEvent::Util (); 116#use AnyEvent::Util (); need to load this in a delayed fashion, as it uses AE::log
114 117
115our $VERSION = $AnyEvent::VERSION; 118our $VERSION = $AnyEvent::VERSION;
116 119
117our ($COLLECT, $FILTER, $LOG); 120our ($COLLECT, $FILTER, $LOG);
118 121
354 357
355 $LOGGER{$logger+0} = $logger; 358 $LOGGER{$logger+0} = $logger;
356 359
357 _reassess $logger+0; 360 _reassess $logger+0;
358 361
362 require AnyEvent::Util;
359 my $guard = AnyEvent::Util::guard { 363 my $guard = AnyEvent::Util::guard (sub {
360 # "clean up" 364 # "clean up"
361 delete $LOGGER{$logger+0}; 365 delete $LOGGER{$logger+0};
362 }; 366 });
363 367
364 sub { 368 sub {
365 $guard if 0; # keep guard alive, but don't cause runtime overhead 369 $guard if 0; # keep guard alive, but don't cause runtime overhead
366 370
367 _log $ctx, $level, @_ 371 _log $ctx, $level, @_
513 } 517 }
514 518
515 @$_ = ($_->[0], (1 << 10) - 1 - 1) 519 @$_ = ($_->[0], (1 << 10) - 1 - 1)
516 for $LOG, $FILTER, $COLLECT; 520 for $LOG, $FILTER, $COLLECT;
517 521
518 $LOG->slaves; 522 #$LOG->slaves;
519 $LOG->title ('$AnyEvent::Log::LOG'); 523 $LOG->title ('$AnyEvent::Log::LOG');
520 $LOG->log_to_warn; 524 $LOG->log_to_warn;
521 525
522 $FILTER->slaves ($LOG); 526 $FILTER->slaves ($LOG);
523 $FILTER->title ('$AnyEvent::Log::FILTER'); 527 $FILTER->title ('$AnyEvent::Log::FILTER');
1088 My::Module=+,file=/tmp/mymodulelog 1092 My::Module=+,file=/tmp/mymodulelog
1089 1093
1090=back 1094=back
1091 1095
1092Any character can be escaped by prefixing it with a C<\> (backslash), as 1096Any character can be escaped by prefixing it with a C<\> (backslash), as
1093usual, so to log to a file containing a comma, colon, backslash and space in the 1097usual, so to log to a file containing a comma, colon, backslash and some
1094filename, you would do this: 1098spaces in the filename, you would do this:
1095 1099
1096 PERL_ANYEVENT_LOG='log=file=/some\ \:file\ with\,\ \\-escapes' 1100 PERL_ANYEVENT_LOG='log=file=/some\ \:file\ with\,\ \\-escapes'
1097 1101
1098Since whitespace (which includes newlines) is allowed, it is fine to 1102Since whitespace (which includes newlines) is allowed, it is fine to
1099specify multiple lines in C<PERL_ANYEVENT_LOG>, e.g.: 1103specify multiple lines in C<PERL_ANYEVENT_LOG>, e.g.:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines