update to match object-remote logging changes
Tyler Riddle [Mon, 5 Nov 2012 04:12:06 +0000 (20:12 -0800)]
bin/system-introspector
lib/System/Introspector/Logger.pm
t/logger.t
t/logsetup.pl

index 2d29bee..2747196 100755 (executable)
@@ -6,7 +6,7 @@ use Pod::Usage;
 use System::Introspector::State;
 use File::Tree::Snapshot;
 use System::Introspector::Config;
-use System::Introspector::Logger qw(:log);
+use System::Introspector::Logger qw(:log get_router);
 use System::Introspector::Logger::VerboseOutput; 
 use System::Introspector::Logger::Output; 
 use System::Introspector::Logger::WarnOutput; 
@@ -18,6 +18,7 @@ GetOptions(
     'g|group=s'     => \my @update_groups,
     'd|debug'       => \my $debug,
     'l|log-level=s' => \my $log_level,
+    'L|log-remote'  => \my $log_remote,
     'h|help'        => sub { pod2usage(0) },
 ) or pod2usage(2);
 
@@ -35,29 +36,19 @@ if (defined($debug) && ! defined($log_level)) {
     $log_level = 'debug';
 }
 
-my ($stderr_destination, $stdout_destination, $warn_destination); 
-my $selector = sub { $_[0]->{package} =~ m/^System::Introspector/; };
-
-#suppress default output if a log level was specified 
 if (defined($log_level)) {
-       $stderr_destination = Object::Remote::LogDestination->new(
-          logger => System::Introspector::Logger::Output->new({ 
-              levels_upto => $log_level,
-          }),
-       )->select(System::Introspector::Logger->arg_router, $selector); 
-           
-} else {
-    $stdout_destination = Object::Remote::LogDestination->new(
-        logger => System::Introspector::Logger::VerboseOutput->new({ 
-            levels => ['info'],
-        }),
-    )->select(System::Introspector::Logger->arg_router, $selector);  
-
-    $warn_destination = Object::Remote::LogDestination->new({
-        logger => System::Introspector::Logger::WarnOutput->new({ 
-            levels_upto => 'warn',
-        }),
-    })->select(System::Introspector::Logger->arg_router, $selector);
+  my $logger = Object::Remote::Logging::Logger->new(
+    min_level => lc($log_level),
+    level_names => Object::Remote::Logging::arg_levels(),
+  );
+
+  get_router()->connect(sub { 
+    return unless $_[1]->{controller} eq 'System::Introspector::Logger';
+    if (! defined $log_remote && defined $_[1]->{object_remote}) {
+        return;
+    }
+    $logger
+  });
 }
 
 $config_file = "$storage_dir/main.conf" unless defined $config_file;
index 3fdea9a..b6c5382 100644 (file)
@@ -1,3 +1,5 @@
+#TODO this should be named ::Logging
+
 package System::Introspector::Logger;
 
 use strictures 1;
index 166f0e9..a05f839 100644 (file)
@@ -1,8 +1,8 @@
 use strictures 1;
 use Test::More;
 
-use System::Introspector::Logger qw ( :log );
+use System::Introspector::Logger qw ( :log get_router);
 
-ok (System::Introspector::Logger->arg_router->does('Log::Contextual::Role::Router'), 'router exists');
+ok (get_router->does('Log::Contextual::Role::Router'), 'router exists');
 
 done_testing;
\ No newline at end of file
index 01c6df7..3c3db5b 100644 (file)
@@ -3,23 +3,20 @@
 
 package System::Introspector::Logger::TestOutput; 
 
-use Log::Contextual::WarnLogger; 
-use base qw ( Log::Contextual::SimpleLogger );
+use base qw ( Object::Remote::Logging::Logger );
 #
 #we want the code blocks in the log lines to execute but not
 #output anything so turn this into a null logger
-sub _log {  }
+sub _output {  }
 
 package main; 
 
-use Object::Remote::Logging qw( :log ); 
-use Object::Remote::LogDestination; 
+use System::Introspector::Logger qw( :log get_router ); 
 #make sure to enable execution of every logging code block
 #by setting the log level as high as it can go
-       my $____LOG_DESTINATION = Object::Remote::LogDestination->new(
-               logger => System::Introspector::Logger::TestOutput->new({ levels_upto => 'trace' }),
-       );      
-       
-       $____LOG_DESTINATION->connect(Object::Remote::Logging->arg_router);
+get_router->connect(System::Introspector::Logger::TestOutput->new(
+  min_level => 'trace', max_level => 'error',
+  level_names => Object::Remote::Logging->arg_levels(),
+));
 1;