From: Tyler Riddle Date: Thu, 6 Sep 2012 15:06:51 +0000 (-0700) Subject: cleaner way to init logs when testing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f68ec2244eb533f6cd9c67fdf4bb07400d185f24;p=scpubgit%2FSystem-Introspector.git cleaner way to init logs when testing --- diff --git a/lib/System/Introspector/Logger.pm b/lib/System/Introspector/Logger.pm index 8c852a4..03ced6a 100644 --- a/lib/System/Introspector/Logger.pm +++ b/lib/System/Introspector/Logger.pm @@ -7,16 +7,19 @@ use System::Introspector::Logger::Output; use Log::Contextual qw( set_logger ); sub init_logging { - my ($self, $level) = @_; + my ($self, $level, $logger) = @_; $level = 'WARN' unless defined $level; + unless(defined($logger)) { + $logger = System::Introspector::Logger::Output->new({ + env_prefix => 'SYSTEM_INTROSPECTOR_LOG', + }); + } #TODO: better way to specify log level? $ENV{SYSTEM_INTROSPECTOR_LOG_UPTO} = $level; - set_logger(System::Introspector::Logger::Output->new({ - env_prefix => 'SYSTEM_INTROSPECTOR_LOG', - })); + set_logger($logger); } diff --git a/lib/System/Introspector/Logger/Output.pm b/lib/System/Introspector/Logger/Output.pm index 97a26ce..e66390d 100644 --- a/lib/System/Introspector/Logger/Output.pm +++ b/lib/System/Introspector/Logger/Output.pm @@ -2,6 +2,7 @@ use strictures 1; package System::Introspector::Logger::Output; +use Log::Contextual::WarnLogger; use base qw ( Log::Contextual::WarnLogger ); sub _log { diff --git a/t/logsetup.pl b/t/logsetup.pl index 5db31d7..5cba5a1 100644 --- a/t/logsetup.pl +++ b/t/logsetup.pl @@ -1,5 +1,25 @@ -#require this in the test to initialize the logging framewor +#require this file in the test to initialize the logging framework #so the tests can run -use System::Introspector::Logger qw( ); -System::Introspector::Logger->init_logging('WARN'); -1; \ No newline at end of file + +package System::Introspector::Logger::TestOutput; + +use Log::Contextual::WarnLogger; +use base qw ( Log::Contextual::SimpleLogger ); +# +#we want the code blocks in the log lines to execute but not +#output anything so turn this into a null logger +sub _log { } + +package main; + +use System::Introspector::Logger qw(); +#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', + System::Introspector::Logger::TestOutput->new({ + levels_upto => 'trace' + }), +); + +1; +