From: Tyler Riddle Date: Thu, 6 Sep 2012 21:07:40 +0000 (-0700) Subject: implement ::Util logging and use Dlog_ methods in some existing probes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5de5e4641c3fc97ae0da394fa5ab6b791d0b8b15;p=scpubgit%2FSystem-Introspector.git implement ::Util logging and use Dlog_ methods in some existing probes --- diff --git a/lib/System/Introspector/Probe/FileHandles.pm b/lib/System/Introspector/Probe/FileHandles.pm index bce6b3e..37473d5 100644 --- a/lib/System/Introspector/Probe/FileHandles.pm +++ b/lib/System/Introspector/Probe/FileHandles.pm @@ -6,7 +6,7 @@ use System::Introspector::Util qw( transform_exceptions ); -use System::Introspector::Logger qw ( :log ); +use System::Introspector::Logger qw ( :log :dlog ); with 'System::Introspector::Role::Probe'; @@ -18,7 +18,7 @@ sub gather { return transform_exceptions { log_trace { "Invoking lsof" }; my @lines = lines_from_command [$self->_lsof_command_call]; - log_trace { "lsof has finished executing" }; + log_trace { "lsof has finished executing" } ; my @handles; for my $line (@lines) { chomp $line; @@ -28,7 +28,7 @@ sub gather { ($1, $2); } @fields }; } - log_trace { "Completed gathering open file information" }; + Dlog_trace { "Completed gathering open file information: $_" } @handles; return { handles => \@handles }; }; } diff --git a/lib/System/Introspector/Probe/Host.pm b/lib/System/Introspector/Probe/Host.pm index c07ecb1..c8b8de1 100644 --- a/lib/System/Introspector/Probe/Host.pm +++ b/lib/System/Introspector/Probe/Host.pm @@ -15,7 +15,7 @@ has hostname_file => (is => 'ro', default => sub {'/etc/hostname' }); sub gather { my ($self) = @_; - log_debug { "Starting to gather host information" }; + log_debug { "Gathering host information" }; return transform_exceptions { return { hostname => $self->_gather_hostname, @@ -38,9 +38,9 @@ my @UnameFields = qw( sub _gather_uname_info { my ($self) = @_; my %uname; + log_trace { "Gathering uname info" }; for my $field (@UnameFields) { (my $option = $field) =~ s{_}{-}g; - log_trace { "Invoking uname with option of '--$option'" }; my $value = output_from_command [uname => "--$option"]; chomp $value; $uname{ $field } = $value; diff --git a/lib/System/Introspector/Util.pm b/lib/System/Introspector/Util.pm index 8681b28..6614357 100644 --- a/lib/System/Introspector/Util.pm +++ b/lib/System/Introspector/Util.pm @@ -7,6 +7,8 @@ use IPC::Open2; use File::Spec; use Scalar::Util qw( blessed ); use Capture::Tiny qw( capture_stderr ); +use System::Introspector::Logger qw( :log :dlog ); + our @EXPORT_OK = qw( handle_from_command @@ -31,6 +33,7 @@ sub is_report_exception { ref(shift) eq 'System::Introspector::_Exception' } sub files_from_dir { my ($dir) = @_; my $dh; + log_trace { "Enumerating files in '$dir'" }; opendir $dh, $dir or fail "Unable to read directory $dir: $!"; my @files; @@ -38,7 +41,7 @@ sub files_from_dir { next if -d "$dir/$item"; push @files, $item; } - return @files; + return Dlog_trace { "File list for '$dir': $_" } @files; } sub transform_exceptions (&) { @@ -57,7 +60,9 @@ sub output_from_command { $in = '' unless defined $in; my ($out, $err) = ('', ''); + Dlog_trace { "executing command with IPC::Run: $_" } @$command; my $ok = eval { run($command, \$in, \$out, \$err) or die $err}; + log_trace { $ok ? "command executed successfully" : "command did not execute successfully" }; $err = $@ unless $ok; return $out, $err, $ok if wantarray; @@ -79,6 +84,7 @@ sub handle_from_command { my ($command) = @_; my $pipe; local $@; + log_trace { "Converting output of '$command' into a readable pipe" }; my $ok = eval { my $out; my $child_pid; @@ -98,6 +104,7 @@ sub handle_from_command { open $pipe, '<', \$content; 1; }; + log_trace { "Completed reading output of '$command'" }; unless ($ok) { my $err = $@; die $err @@ -109,8 +116,10 @@ sub handle_from_command { sub handle_from_file { my ($file) = @_; + log_trace { "Creating filehandle for file '$file'" }; open my $fh, '<', $file or fail "Unable to read $file: $!"; + log_trace { "Finished opening '$file'" }; return $fh; }