From: Tyler Riddle Date: Thu, 13 Sep 2012 00:24:44 +0000 (-0700) Subject: integrate in new routed logging support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a270caa079b3e6d5175fdc2145788cc539c64394;p=scpubgit%2FSystem-Introspector.git integrate in new routed logging support --- diff --git a/lib/System/Introspector/Config.pm b/lib/System/Introspector/Config.pm index 81174c8..b54b7b0 100644 --- a/lib/System/Introspector/Config.pm +++ b/lib/System/Introspector/Config.pm @@ -7,7 +7,8 @@ has config => (is => 'lazy'); has config_file => (is => 'ro', required => 1); -has log_level => (is => 'lazy'); +#TODO pull these out +#has log_level => (is => 'lazy'); sub _build_config { my ($self) = @_; @@ -17,9 +18,9 @@ sub _build_config { return \%config; } -sub _build_log_level { - return $_[0]->config->{log_level}; -} +#sub _build_log_level { +# return $_[0]->config->{log_level}; +#} sub sudo_user { $_[0]->config->{sudo_user} } diff --git a/lib/System/Introspector/Gatherer.pm b/lib/System/Introspector/Gatherer.pm index f9359ea..052f130 100644 --- a/lib/System/Introspector/Gatherer.pm +++ b/lib/System/Introspector/Gatherer.pm @@ -12,11 +12,12 @@ has introspectors => (is => 'ro', required => 1); #where logging has not been initialized yet so #it must be initialized again before the probe can #run -sub init_logging { - my ($self, $log_level, $context) = @_; - System::Introspector::Logger->init_logging($log_level, $context); - return $self; -} +#TODO waiting to see if this really is never coming back +#sub init_logging { +# my ($self, $log_level, $context) = @_; +# System::Introspector::Logger->init_logging($context); +# return $self; +#} sub gather_all { my ($self) = @_; diff --git a/lib/System/Introspector/Logger.pm b/lib/System/Introspector/Logger.pm index c39fa59..fd460a4 100644 --- a/lib/System/Introspector/Logger.pm +++ b/lib/System/Introspector/Logger.pm @@ -4,30 +4,35 @@ package System::Introspector::Logger; use base qw(Log::Contextual); use System::Introspector::Logger::Output; -use Log::Contextual qw( set_logger ); +use Log::Contextual qw( :log ); +use Log::Contextual::Destination; + +sub arg_router { $_[1] || Log::Contextual::Router::Dynamic->new } #should always pass in log level and execution context; #specifying a logger is used when logging during #testing so a null output logging class can be used -sub init_logging { - my ($self, $level, $context, $logger) = @_; - - $level = 'WARN' unless defined $level; - unless(defined($logger)) { - $logger = System::Introspector::Logger::Output->new({ - env_prefix => 'SYSTEM_INTROSPECTOR_LOG', - }); - - $logger->set_execution_context($context); - } - - #TODO: better way to specify log level? - $ENV{SYSTEM_INTROSPECTOR_LOG_UPTO} = $level; - - set_logger($logger); - - return 1; -} +#TODO waiting to see if this really is never coming back +#sub init_logging { +# my ($self, $level, $context, $output) = @_; +# +# $level = 'WARN' unless defined $level; +# #TODO: better way to specify log level? +# $ENV{SYSTEM_INTROSPECTOR_LOG_UPTO} = $level; +# +# unless(defined($output)) { +# $output = System::Introspector::Logger::Output->new({ +# env_prefix => 'SYSTEM_INTROSPECTOR_LOG', +# }); +# +# $output->set_execution_context($context); +# } +# +# my $dest = Log::Contextual::Destination->new(logger => $output); +# $dest->connect($self->get_router); +# +# return 1; +#} 1; \ No newline at end of file diff --git a/lib/System/Introspector/Logger/Output.pm b/lib/System/Introspector/Logger/Output.pm index 897dff5..cd7b8bf 100644 --- a/lib/System/Introspector/Logger/Output.pm +++ b/lib/System/Introspector/Logger/Output.pm @@ -1,9 +1,11 @@ -use strictures 1; - package System::Introspector::Logger::Output; -use Log::Contextual::WarnLogger; -use base qw ( Log::Contextual::WarnLogger ); +use strictures 1; + +#using simple logger because the configuration +#interface is slightly nicer +use Log::Contextual::SimpleLogger; +use base qw ( Log::Contextual::SimpleLogger ); sub set_execution_context { my ($self, $context_name) = @_; diff --git a/lib/System/Introspector/Probe/FileHandles.pm b/lib/System/Introspector/Probe/FileHandles.pm index 37473d5..472b631 100644 --- a/lib/System/Introspector/Probe/FileHandles.pm +++ b/lib/System/Introspector/Probe/FileHandles.pm @@ -28,7 +28,7 @@ sub gather { ($1, $2); } @fields }; } - Dlog_trace { "Completed gathering open file information: $_" } @handles; + log_trace { "Completed gathering open file information" }; return { handles => \@handles }; }; } diff --git a/lib/System/Introspector/State.pm b/lib/System/Introspector/State.pm index 5ce21eb..7c89a4a 100644 --- a/lib/System/Introspector/State.pm +++ b/lib/System/Introspector/State.pm @@ -14,10 +14,11 @@ sub user { $_[0]->config->user } sub sudo_user { $_[0]->config->sudo_user } -sub BUILD { - my ($self) = @_; - System::Introspector::Logger->init_logging($self->config->log_level, 'controller'); -} +#TODO waiting to see if this really is never coming back +#sub BUILD { +# my ($self) = @_; +# System::Introspector::Logger->init_logging('controller'); +#} sub gather { my ($self, @groups) = @_; @@ -140,7 +141,8 @@ sub _create_gatherer { host => $arg{host}, sudo_user => $arg{sudo} && $self->sudo_user, introspectors => $arg{introspectors}, - )->init_logging($self->config->log_level, "probe:$arg{host}"); + #TODO waiting to see if this really is never coming back + );#->init_logging($self->config->log_level, "probe:$arg{host}"); } 1; diff --git a/t/logger.t b/t/logger.t index 2cfaac3..b01720c 100644 --- a/t/logger.t +++ b/t/logger.t @@ -3,6 +3,6 @@ use Test::More; use System::Introspector::Logger qw ( :log ); -ok (System::Introspector::Logger->init_logging('TRACE', 'testing logging system'), 'initialize logging'); +ok (System::Introspector::Logger->get_router->does('Log::Contextual::Role::Router'), 'router exists'); done_testing; \ No newline at end of file diff --git a/t/logsetup.pl b/t/logsetup.pl index 43ba184..75de5e7 100644 --- a/t/logsetup.pl +++ b/t/logsetup.pl @@ -12,14 +12,14 @@ sub _log { } package main; -use System::Introspector::Logger qw(); +use System::Introspector::Logger qw( :log ); #make sure to enable execution of every logging code block #by setting the log level as high as it can go -System::Introspector::Logger->init_logging('TRACE', 'test', - System::Introspector::Logger::TestOutput->new({ - levels_upto => 'trace' - }), -); + my $____LOG_DESTINATION = Log::Contextual::Destination->new( + logger => System::Introspector::Logger::TestOutput->new({ levels_upto => 'trace' }), + ); + + $____LOG_DESTINATION->connect(System::Introspector::Logger->get_root_router); 1;