update command line logging feature
Tyler Riddle [Thu, 13 Sep 2012 00:25:34 +0000 (17:25 -0700)]
bin/system-introspector

index 88e88ae..ece49c7 100755 (executable)
@@ -6,7 +6,11 @@ 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); 
+use Log::Contextual::Destination;
+use Log::Contextual::SimpleLogger; 
+use Object::Remote::Logging qw( );     
+
 
 GetOptions(
     'c|config=s'    => \my $config_file,
@@ -27,18 +31,28 @@ die "Requires --config\n"
 die "Requires --all or --group option\n"
     unless $update_all or @update_groups;
 
-#command line arguments override the logging configuration
-#and --log-level overrides -d
+#--log-level overrides -d
 if (defined($debug) && ! defined($log_level)) {
-    $log_level = 'DEBUG';
+    $log_level = 'debug';
 }
 
-$config_file = "$storage_dir/main.conf" unless defined $config_file;
+my $log_destination; 
+if (defined($log_level)) {
+warn "$log_level";
+       $log_destination = Log::Contextual::Destination->new(
+               logger => Log::Contextual::SimpleLogger->new({ levels_upto => $log_level }),
+       );      
+       
+    $log_destination->connect(System::Introspector::Logger->get_router);
+    #$log_destination->connect(Log::Contextual->get_root_router);
+    #TODO attaching to this router does't work here because of
+    #timming issue
+    #$log_destination->connect(Object::Remote::Logging->get_router);
+}
 
-my %config_args = (config_file => $config_file); 
-$config_args{log_level} = $log_level if defined $log_level; 
+$config_file = "$storage_dir/main.conf" unless defined $config_file;
 
-my $config = System::Introspector::Config->new(%config_args);
+my $config = System::Introspector::Config->new(config_file => $config_file);
 
 $config->has_group($_) or die "Unknown group '$_'\n"
     for @update_groups;