… | |
… | |
1053 | |
1053 | |
1054 | =item AnyEvent::log $level, $msg[, @args] |
1054 | =item AnyEvent::log $level, $msg[, @args] |
1055 | |
1055 | |
1056 | Log the given C<$msg> at the given C<$level>. |
1056 | Log the given C<$msg> at the given C<$level>. |
1057 | |
1057 | |
1058 | Loads AnyEvent::Log on first use and calls C<AnyEvent::Log::log> - |
1058 | If L<AnyEvent::Log> is not loaded then this function makes a simple test |
|
|
1059 | to see whether the message will be logged. If the test succeeds it will |
|
|
1060 | load AnyEvent::Log and call C<AnyEvent::Log::log> - consequently, look at |
1059 | consequently, look at the L<AnyEvent::Log> documentation for details. |
1061 | the L<AnyEvent::Log> documentation for details. |
|
|
1062 | |
|
|
1063 | If the test fails it will simply return. |
1060 | |
1064 | |
1061 | If you want to sprinkle loads of logging calls around your code, consider |
1065 | If you want to sprinkle loads of logging calls around your code, consider |
1062 | creating a logger callback with the C<AnyEvent::Log::logger> function. |
1066 | creating a logger callback with the C<AnyEvent::Log::logger> function, |
|
|
1067 | which can reduce typing, codesize and can reduce the logging overhead |
|
|
1068 | enourmously. |
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 | |
1295 | sub log($$;@) { |
1301 | sub 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 | |
1304 | if (length $ENV{PERL_ANYEVENT_LOG}) { |
1312 | if (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 | |
1560 | sub time { |
1568 | sub 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 | |
1674 | sub signal { |
1681 | sub 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 (); |
… | |
… | |
2033 | conditions. You can set this environment variable to make AnyEvent more |
2038 | conditions. You can set this environment variable to make AnyEvent more |
2034 | talkative. If you want to do more than just set the global logging level |
2039 | talkative. If you want to do more than just set the global logging level |
2035 | you should have a look at C<PERL_ANYEVENT_LOG>, which allows much more |
2040 | you should have a look at C<PERL_ANYEVENT_LOG>, which allows much more |
2036 | complex specifications. |
2041 | complex specifications. |
2037 | |
2042 | |
2038 | When set to C<5> or higher, causes AnyEvent to warn about unexpected |
2043 | When set to C<5> or higher (warn), causes AnyEvent to warn about unexpected |
2039 | conditions, such as not being able to load the event model specified by |
2044 | conditions, such as not being able to load the event model specified by |
2040 | C<PERL_ANYEVENT_MODEL>. |
2045 | C<PERL_ANYEVENT_MODEL>, or a guard callback throwing an exception - this |
|
|
2046 | is the minimum recommended level. |
2041 | |
2047 | |
2042 | When set to C<7> or higher, cause AnyEvent to report to STDERR which event |
2048 | When set to C<7> or higher (info), cause AnyEvent to report which event model it |
2043 | model it chooses. |
2049 | chooses. |
2044 | |
2050 | |
2045 | When set to C<8> or higher, then AnyEvent will report extra information on |
2051 | When set to C<8> or higher (debug), then AnyEvent will report extra information on |
2046 | which optional modules it loads and how it implements certain features. |
2052 | which 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 | |
2050 | Accepts rather complex logging specifications. For example, you could log |
2056 | Accepts rather complex logging specifications. For example, you could log |
… | |
… | |
2052 | stderr, and errors and above to syslog, with: |
2058 | stderr, 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 | |
2056 | For the rather extensive details, see L<AnyEvent::Log>. |
2062 | For the rather extensive details, see L<AnyEvent::Log>. |
|
|
2063 | |
|
|
2064 | This variable is evaluated when AnyEvent (or L<AnyEvent::Log>) is loaded, |
|
|
2065 | so will take effect even before AnyEvent has initialised itself. |
2057 | |
2066 | |
2058 | Note that specifying this environment variable causes the L<AnyEvent::Log> |
2067 | Note that specifying this environment variable causes the L<AnyEvent::Log> |
2059 | module to be loaded, while C<PERL_ANYEVENT_VERBOSE> does not, so only |
2068 | module to be loaded, while C<PERL_ANYEVENT_VERBOSE> does not, so only |
2060 | using the latter saves a few hundred kB of memory until the first message |
2069 | using the latter saves a few hundred kB of memory until the first message |
2061 | is being logged. |
2070 | is being logged. |
… | |
… | |
2080 | If this env variable is set, then its contents will be interpreted by |
2089 | If this env variable is set, then its contents will be interpreted by |
2081 | C<AnyEvent::Socket::parse_hostport> (after replacing every occurance of |
2090 | C<AnyEvent::Socket::parse_hostport> (after replacing every occurance of |
2082 | C<$$> by the process pid) and an C<AnyEvent::Debug::shell> is bound on |
2091 | C<$$> by the process pid) and an C<AnyEvent::Debug::shell> is bound on |
2083 | that port. The shell object is saved in C<$AnyEvent::Debug::SHELL>. |
2092 | that port. The shell object is saved in C<$AnyEvent::Debug::SHELL>. |
2084 | |
2093 | |
2085 | This takes place when the first watcher is created. |
2094 | This happens when the first watcher is created. |
2086 | |
2095 | |
2087 | For example, to bind a debug shell on a unix domain socket in |
2096 | For example, to bind a debug shell on a unix domain socket in |
2088 | F<< /tmp/debug<pid>.sock >>, you could use this: |
2097 | F<< /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 |