From: Tyler Riddle Date: Sat, 10 Nov 2012 22:50:21 +0000 (-0800) Subject: -q command line argument stops all log output; logger output integrated into cli... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Flogging;p=scpubgit%2FSystem-Introspector-Report.git -q command line argument stops all log output; logger output integrated into cli tool --- diff --git a/bin/system-introspector-report b/bin/system-introspector-report index 2aa6c04..a338d5d 100755 --- a/bin/system-introspector-report +++ b/bin/system-introspector-report @@ -5,7 +5,8 @@ use Pod::Usage; use Try::Tiny; use System::Introspector::Report::Source; use System::Introspector::Report::Config; -use System::Introspector::Report::Logging qw( :log router ); +use System::Introspector::Report::Logging qw( :log router arg_levels); +use Object::Remote::Logging::Logger; GetOptions( 's|storage=s' => \my $storage_dir, @@ -14,6 +15,7 @@ GetOptions( 'p|publish=s' => \my @publish_types, 'a|all' => \my $all_reports, 'v|verbose+' => \my $log_verbose, + 'q|quiet+' => \my $log_quiet, 'h|help' => sub { pod2usage(0) }, ) or pod2usage(2); @@ -25,6 +27,34 @@ die "$0 requires --config (-c) to be specified\n" my $timed = sub { sprintf shift, scalar localtime }; +my $log_level; + +if (defined $log_quiet) { + $log_level = undef; +} elsif (! defined $log_verbose) { + $log_level = 'info'; +} elsif ($log_verbose == 1) { + $log_level = 'verbose'; +} elsif ($log_verbose == 2) { + $log_level = 'debug'; +} elsif ($log_verbose == 3) { + $log_level = 'trace'; +} else { + die "too many -v specified"; +} + +if (defined($log_level)) { + my $logger = Object::Remote::Logging::Logger->new( + min_level => lc($log_level), level_names => arg_levels, + format => '%s', + ); + + router()->connect(sub { + return unless $_[1]->{controller} eq 'System::Introspector::Report::Logging'; + $logger + }); +} + log_info { 'Starting at %s'->$timed }; my $config = System::Introspector::Report::Config diff --git a/lib/System/Introspector/Report/Source.pm b/lib/System/Introspector/Report/Source.pm index 0ec6501..4206ec1 100644 --- a/lib/System/Introspector/Report/Source.pm +++ b/lib/System/Introspector/Report/Source.pm @@ -28,7 +28,6 @@ sub generate { my @dirs = $self->_find_source_dirs; for my $dir_spec (@dirs) { my ($id, $path) = @$dir_spec; - log_debug { "Starting to load dataset for node '$id' from '$path' " }; my $data = $self->_load_dataset($path, $required) or next; log_verbose { "Collecting data from node '$id'" };