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.37 by root, Thu Aug 25 06:34:11 2011 UTC vs.
Revision 1.38 by root, Fri Aug 26 00:32:45 2011 UTC

206 info => 7, 206 info => 7,
207 debug => 8, 207 debug => 8,
208 trace => 9, 208 trace => 9,
209); 209);
210 210
211sub now () { time } 211our $TIME_EXACT;
212
213sub exact_time($) {
214 $TIME_EXACT = shift;
215 *_ts = $AnyEvent::MODEL
216 ? $TIME_EXACT ? \&AE::now : \&AE::time
217 : sub () { $TIME_EXACT ? do { require Time::HiRes; Time::HiRes::time () } : time };
218}
219
220BEGIN {
221 exact_time 0;
222}
212 223
213AnyEvent::post_detect { 224AnyEvent::post_detect {
214 *now = \&AE::now; 225 exact_time $TIME_EXACT;
215}; 226};
216 227
217our @LEVEL2STR = qw(0 fatal alert crit error warn note info debug trace); 228our @LEVEL2STR = qw(0 fatal alert crit error warn note info debug trace);
218 229
219# time, ctx, level, msg 230# time, ctx, level, msg
252 # now get raw message, unless we have it already 263 # now get raw message, unless we have it already
253 unless ($now) { 264 unless ($now) {
254 $format = $format->() if ref $format; 265 $format = $format->() if ref $format;
255 $format = sprintf $format, @args if @args; 266 $format = sprintf $format, @args if @args;
256 $format =~ s/\n$//; 267 $format =~ s/\n$//;
257 $now = now; 268 $now = _ts;
258 }; 269 };
259 270
260 # format msg 271 # format msg
261 my $str = $ctx->[4] 272 my $str = $ctx->[4]
262 ? $ctx->[4]($now, $_[0], $level, $format) 273 ? $ctx->[4]($now, $_[0], $level, $format)
376sub logger($;$) { 387sub logger($;$) {
377 _logger 388 _logger
378 $CTX{ (caller)[0] } ||= _pkg_ctx +(caller)[0], 389 $CTX{ (caller)[0] } ||= _pkg_ctx +(caller)[0],
379 @_ 390 @_
380} 391}
392
393=item AnyEvent::Log::exact_time $on
394
395By default, C<AnyEvent::Log> will use C<AE::now>, i.e. the cached
396eventloop time, for the log timestamps. After calling this function with a
397true value it will instead resort to C<AE::time>, i.e. fetch the current
398time on each log message. This only makes a difference for event loops
399that actually cache the time (such as L<EV> or L<AnyEvent::Loop>).
400
401Since C<AnyEvent::Log> has to work even before the L<AnyEvent> has been
402initialised, this switch will also decide whether to use C<CORE::time> or
403C<Time::HiRes::time> when logging a message before L<AnyEvent> becomes
404available.
381 405
382=back 406=back
383 407
384=head1 LOGGING CONTEXTS 408=head1 LOGGING CONTEXTS
385 409

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines