fix bug that allowed forwarded logs to be output from the logger built via env vars
[scpubgit/Object-Remote.git] / lib / Object / Remote / Logging.pm
index df4134f..7eee65f 100644 (file)
@@ -46,23 +46,23 @@ sub before_import {
 }
 
 sub _parse_selections {
-    my ($selections_string) = @_;
-    my %log_ok;
+  my ($selections_string) = @_;
+  my %log_ok;
     
-    #example string:
-    #"  * -Object::Remote::Logging    Foo::Bar::Baz   "
-    foreach(split(/\s+/, $selections_string)) {
-        next if $_ eq '';
-        if ($_ eq '*') {
-            $log_ok{$_} = 1;
-        } elsif (s/^-//) {
-            $log_ok{$_} = 0;
-        } else {
-            $log_ok{$_} = 1;
-        }
+  #example string:
+  #"  * -Object::Remote::Logging    Foo::Bar::Baz   "
+  foreach(split(/\s+/, $selections_string)) {
+    next if $_ eq '';
+    if ($_ eq '*') {
+      $log_ok{$_} = 1;
+    } elsif (s/^-//) {
+      $log_ok{$_} = 0;
+    } else {
+      $log_ok{$_} = 1;
     }
+  }
     
-    return %log_ok;
+  return %log_ok;
 }
 
 #this is invoked on all nodes
@@ -70,16 +70,20 @@ sub init_logging {
   my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL};
   my $format = $ENV{OBJECT_REMOTE_LOG_FORMAT};
   my $selections = $ENV{OBJECT_REMOTE_LOG_SELECTIONS};
+  my $test_logging = $ENV{OBJECT_REMOTE_TEST_LOGGER};
   my %controller_should_log;
   
   unless (defined $ENV{OBJECT_REMOTE_LOG_FORWARDING} && $ENV{OBJECT_REMOTE_LOG_FORWARDING} ne '') {
     $ENV{OBJECT_REMOTE_LOG_FORWARDING} = 1;
   }
-
-  return unless defined $level && $level ne '';
-  $format = "[%l %r] %s" unless defined $format;
-  $selections = __PACKAGE__ unless defined $selections;
-  %controller_should_log = _parse_selections($selections);
+  
+  if ($test_logging) {
+    require Object::Remote::Logging::TestLogger;
+    router->connect(Object::Remote::Logging::TestLogger->new(
+      min_level => 'trace', max_level => 'error',
+      level_names => Object::Remote::Logging->arg_levels(),
+    ));
+  }
 
   {
     no warnings 'once';
@@ -90,6 +94,12 @@ sub init_logging {
     } 
   }
 
+  return unless defined $level && $level ne '';
+  
+  $format = "[%l %r] %s" unless defined $format;
+  $selections = __PACKAGE__ unless defined $selections;
+  %controller_should_log = _parse_selections($selections);
+
   my $logger = Object::Remote::Logging::Logger->new(
     min_level => lc($level), format => $format,
     level_names => Object::Remote::Logging::arg_levels(),
@@ -104,7 +114,7 @@ sub init_logging {
     return unless $will_log;
     #skip things from remote hosts because they log to STDERR
     #when OBJECT_REMOTE_LOG_LEVEL is in effect
-    return if $_[1]->{remote}->{connection_id};
+    return if $_[1]->{remote}->{object_remote};
     $logger
   });
 }
@@ -115,9 +125,6 @@ sub init_remote_logging {
   my ($self, %controller_info) = @_;
   
   router()->_remote_metadata(\%controller_info);
-  #TODO having an instance of an object in the remote interpreter causes it to hang
-  #on exit intermitently or leave a zombie laying around frequently - not a bug limited
-  #to log forwarding
   router()->_forward_destination($controller_info{router}) if $ENV{OBJECT_REMOTE_LOG_FORWARDING};
 }