ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.373 by root, Thu Aug 25 03:08:48 2011 UTC vs.
Revision 1.376 by root, Thu Aug 25 06:34:11 2011 UTC

1053 1053
1054=item AnyEvent::log $level, $msg[, @args] 1054=item AnyEvent::log $level, $msg[, @args]
1055 1055
1056Log the given C<$msg> at the given C<$level>. 1056Log the given C<$msg> at the given C<$level>.
1057 1057
1058Loads AnyEvent::Log on first use and calls C<AnyEvent::Log::log> - 1058If L<AnyEvent::Log> is not loaded then this function makes a simple test
1059to see whether the message will be logged. If the test succeeds it will
1060load AnyEvent::Log and call C<AnyEvent::Log::log> - consequently, look at
1059consequently, look at the L<AnyEvent::Log> documentation for details. 1061the L<AnyEvent::Log> documentation for details.
1062
1063If the test fails it will simply return.
1060 1064
1061If you want to sprinkle loads of logging calls around your code, consider 1065If you want to sprinkle loads of logging calls around your code, consider
1062creating a logger callback with the C<AnyEvent::Log::logger> function. 1066creating a logger callback with the C<AnyEvent::Log::logger> function,
1067which can reduce typing, codesize and can reduce the logging overhead
1068enourmously.
1063 1069
1064=back 1070=back
1065 1071
1066=head1 WHAT TO DO IN A MODULE 1072=head1 WHAT TO DO IN A MODULE
1067 1073
1291 1297
1292 () 1298 ()
1293} 1299}
1294 1300
1295sub log($$;@) { 1301sub log($$;@) {
1296 # only load the bug bloated module when we actually are about to log something 1302 # only load the big bloated module when we actually are about to log something
1297 if ($_[0] <= $VERBOSE) { 1303 if ($_[0] <= $VERBOSE) { # also catches non-numeric levels(!)
1298 require AnyEvent::Log; 1304 require AnyEvent::Log;
1299 # AnyEvent::Log overwrites this function 1305 # AnyEvent::Log overwrites this function
1300 goto &log; 1306 goto &log;
1301 } 1307 }
1308
1309 0 # not logged
1302} 1310}
1303 1311
1304if (length $ENV{PERL_ANYEVENT_LOG}) { 1312if (length $ENV{PERL_ANYEVENT_LOG}) {
1305 require AnyEvent::Log; # AnyEvent::Log does the thing for us 1313 require AnyEvent::Log; # AnyEvent::Log does the thing for us
1306} 1314}
1371 $model = "AnyEvent::Impl::$model" unless $model =~ s/::$//; 1379 $model = "AnyEvent::Impl::$model" unless $model =~ s/::$//;
1372 if (eval "require $model") { 1380 if (eval "require $model") {
1373 AnyEvent::log 7 => "loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it."; 1381 AnyEvent::log 7 => "loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it.";
1374 $MODEL = $model; 1382 $MODEL = $model;
1375 } else { 1383 } else {
1376 AnyEvent::log warn => "unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@"; 1384 AnyEvent::log 5 => "unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@";
1377 } 1385 }
1378 } 1386 }
1379 1387
1380 # check for already loaded models 1388 # check for already loaded models
1381 unless ($MODEL) { 1389 unless ($MODEL) {
1559 1567
1560sub time { 1568sub time {
1561 eval q{ # poor man's autoloading {} 1569 eval q{ # poor man's autoloading {}
1562 # probe for availability of Time::HiRes 1570 # probe for availability of Time::HiRes
1563 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { 1571 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") {
1564 AnyEvent::log 8 => "AnyEvent: using Time::HiRes for sub-second timing accuracy."
1565 if $AnyEvent::VERBOSE >= 8;
1566 *time = sub { Time::HiRes::time () }; 1572 *time = sub { Time::HiRes::time () };
1567 *AE::time = \& Time::HiRes::time ; 1573 *AE::time = \& Time::HiRes::time ;
1574 *now = \&time;
1575 AnyEvent::log 8 => "AnyEvent: using Time::HiRes for sub-second timing accuracy.";
1568 # if (eval "use POSIX (); (POSIX::times())... 1576 # if (eval "use POSIX (); (POSIX::times())...
1569 } else { 1577 } else {
1570 AnyEvent::log critical => "using built-in time(), WARNING, no sub-second resolution!";
1571 *time = sub { CORE::time }; 1578 *time = sub { CORE::time };
1572 *AE::time = sub (){ CORE::time }; 1579 *AE::time = sub (){ CORE::time };
1580 *now = \&time;
1581 AnyEvent::log 3 => "using built-in time(), WARNING, no sub-second resolution!";
1573 } 1582 }
1574
1575 *now = \&time;
1576 }; 1583 };
1577 die if $@; 1584 die if $@;
1578 1585
1579 &time 1586 &time
1580} 1587}
1673 1680
1674sub signal { 1681sub signal {
1675 eval q{ # poor man's autoloading {} 1682 eval q{ # poor man's autoloading {}
1676 # probe for availability of Async::Interrupt 1683 # probe for availability of Async::Interrupt
1677 if (_have_async_interrupt) { 1684 if (_have_async_interrupt) {
1678 AnyEvent::log 8 => "using Async::Interrupt for race-free signal handling." 1685 AnyEvent::log 8 => "using Async::Interrupt for race-free signal handling.";
1679 if $AnyEvent::VERBOSE >= 8;
1680 1686
1681 $SIGPIPE_R = new Async::Interrupt::EventPipe; 1687 $SIGPIPE_R = new Async::Interrupt::EventPipe;
1682 $SIG_IO = AE::io $SIGPIPE_R->fileno, 0, \&_signal_exec; 1688 $SIG_IO = AE::io $SIGPIPE_R->fileno, 0, \&_signal_exec;
1683 1689
1684 } else { 1690 } else {
1685 AnyEvent::log 8 => "using emulated perl signal handling with latency timer." 1691 AnyEvent::log 8 => "using emulated perl signal handling with latency timer.";
1686 if $AnyEvent::VERBOSE >= 8;
1687 1692
1688 if (AnyEvent::WIN32) { 1693 if (AnyEvent::WIN32) {
1689 require AnyEvent::Util; 1694 require AnyEvent::Util;
1690 1695
1691 ($SIGPIPE_R, $SIGPIPE_W) = AnyEvent::Util::portable_pipe (); 1696 ($SIGPIPE_R, $SIGPIPE_W) = AnyEvent::Util::portable_pipe ();
2033conditions. You can set this environment variable to make AnyEvent more 2038conditions. You can set this environment variable to make AnyEvent more
2034talkative. If you want to do more than just set the global logging level 2039talkative. If you want to do more than just set the global logging level
2035you should have a look at C<PERL_ANYEVENT_LOG>, which allows much more 2040you should have a look at C<PERL_ANYEVENT_LOG>, which allows much more
2036complex specifications. 2041complex specifications.
2037 2042
2038When set to C<5> or higher, causes AnyEvent to warn about unexpected 2043When set to C<5> or higher (warn), causes AnyEvent to warn about unexpected
2039conditions, such as not being able to load the event model specified by 2044conditions, such as not being able to load the event model specified by
2040C<PERL_ANYEVENT_MODEL>. 2045C<PERL_ANYEVENT_MODEL>, or a guard callback throwing an exception - this
2046is the minimum recommended level.
2041 2047
2042When set to C<7> or higher, cause AnyEvent to report to STDERR which event 2048When set to C<7> or higher (info), cause AnyEvent to report which event model it
2043model it chooses. 2049chooses.
2044 2050
2045When set to C<8> or higher, then AnyEvent will report extra information on 2051When set to C<8> or higher (debug), then AnyEvent will report extra information on
2046which optional modules it loads and how it implements certain features. 2052which optional modules it loads and how it implements certain features.
2047 2053
2048=item C<PERL_ANYEVENT_LOG> 2054=item C<PERL_ANYEVENT_LOG>
2049 2055
2050Accepts rather complex logging specifications. For example, you could log 2056Accepts rather complex logging specifications. For example, you could log
2052stderr, and errors and above to syslog, with: 2058stderr, and errors and above to syslog, with:
2053 2059
2054 PERL_ANYEVENT_LOG=Some::Module=debug,+log:filter=warn,+%syslog:%syslog=error,syslog 2060 PERL_ANYEVENT_LOG=Some::Module=debug,+log:filter=warn,+%syslog:%syslog=error,syslog
2055 2061
2056For the rather extensive details, see L<AnyEvent::Log>. 2062For the rather extensive details, see L<AnyEvent::Log>.
2063
2064This variable is evaluated when AnyEvent (or L<AnyEvent::Log>) is loaded,
2065so will take effect even before AnyEvent has initialised itself.
2057 2066
2058Note that specifying this environment variable causes the L<AnyEvent::Log> 2067Note that specifying this environment variable causes the L<AnyEvent::Log>
2059module to be loaded, while C<PERL_ANYEVENT_VERBOSE> does not, so only 2068module to be loaded, while C<PERL_ANYEVENT_VERBOSE> does not, so only
2060using the latter saves a few hundred kB of memory until the first message 2069using the latter saves a few hundred kB of memory until the first message
2061is being logged. 2070is being logged.
2080If this env variable is set, then its contents will be interpreted by 2089If this env variable is set, then its contents will be interpreted by
2081C<AnyEvent::Socket::parse_hostport> (after replacing every occurance of 2090C<AnyEvent::Socket::parse_hostport> (after replacing every occurance of
2082C<$$> by the process pid) and an C<AnyEvent::Debug::shell> is bound on 2091C<$$> by the process pid) and an C<AnyEvent::Debug::shell> is bound on
2083that port. The shell object is saved in C<$AnyEvent::Debug::SHELL>. 2092that port. The shell object is saved in C<$AnyEvent::Debug::SHELL>.
2084 2093
2085This takes place when the first watcher is created. 2094This happens when the first watcher is created.
2086 2095
2087For example, to bind a debug shell on a unix domain socket in 2096For example, to bind a debug shell on a unix domain socket in
2088F<< /tmp/debug<pid>.sock >>, you could use this: 2097F<< /tmp/debug<pid>.sock >>, you could use this:
2089 2098
2090 PERL_ANYEVENT_DEBUG_SHELL=/tmp/debug\$\$.sock perlprog 2099 PERL_ANYEVENT_DEBUG_SHELL=/tmp/debug\$\$.sock perlprog

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines