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.387 by root, Sat Oct 1 22:39:29 2011 UTC vs.
Revision 1.389 by root, Tue Oct 4 05:34:50 2011 UTC

1302} 1302}
1303 1303
1304sub log($$;@) { 1304sub log($$;@) {
1305 # only load the big bloated module when we actually are about to log something 1305 # only load the big bloated module when we actually are about to log something
1306 if ($_[0] <= ($VERBOSE || 1)) { # also catches non-numeric levels(!) and fatal 1306 if ($_[0] <= ($VERBOSE || 1)) { # also catches non-numeric levels(!) and fatal
1307 local ($!, $@);
1307 require AnyEvent::Log; # among other things, sets $VERBOSE to 9 1308 require AnyEvent::Log; # among other things, sets $VERBOSE to 9
1308 # AnyEvent::Log overwrites this function 1309 # AnyEvent::Log overwrites this function
1309 goto &log; 1310 goto &log;
1310 } 1311 }
1311 1312
1312 0 # not logged 1313 0 # not logged
1313} 1314}
1314 1315
1315sub logger($;$) { 1316sub _logger($;$) {
1316 package AnyEvent::Log;
1317
1318 my ($level, $renabled) = @_; 1317 my ($level, $renabled) = @_;
1319 1318
1320 $$renabled = $level <= $VERBOSE; 1319 $$renabled = $level <= $VERBOSE;
1321 1320
1322 my $pkg = (caller)[0];
1323
1324 my $logger = [$pkg, $level, $renabled]; 1321 my $logger = [(caller)[0], $level, $renabled];
1325 1322
1326 our %LOGGER;
1327 $LOGGER{$logger+0} = $logger; 1323 $AnyEvent::Log::LOGGER{$logger+0} = $logger;
1328 1324
1325# return unless defined wantarray;
1326#
1329 require AnyEvent::Util; 1327# require AnyEvent::Util;
1330 my $guard = AnyEvent::Util::guard (sub { 1328# my $guard = AnyEvent::Util::guard (sub {
1331 # "clean up" 1329# # "clean up"
1332 delete $LOGGER{$logger+0}; 1330# delete $LOGGER{$logger+0};
1333 }); 1331# });
1334 1332#
1335 sub { 1333# sub {
1336 return 0 unless $$renabled; 1334# return 0 unless $$renabled;
1337 1335#
1338 $guard if 0; # keep guard alive, but don't cause runtime overhead 1336# $guard if 0; # keep guard alive, but don't cause runtime overhead
1339 require AnyEvent::Log unless $AnyEvent::Log::VERSION; 1337# require AnyEvent::Log unless $AnyEvent::Log::VERSION;
1340 package AnyEvent::Log; 1338# package AnyEvent::Log;
1341 _log ($logger->[0], $level, @_) # logger->[0] has been converted at load time 1339# _log ($logger->[0], $level, @_) # logger->[0] has been converted at load time
1342 } 1340# }
1343} 1341}
1344 1342
1345if (length $ENV{PERL_ANYEVENT_LOG}) { 1343if (length $ENV{PERL_ANYEVENT_LOG}) {
1346 require AnyEvent::Log; # AnyEvent::Log does the thing for us 1344 require AnyEvent::Log; # AnyEvent::Log does the thing for us
1347} 1345}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines