From: Tyler Riddle Date: Thu, 6 Sep 2012 19:56:41 +0000 (-0700) Subject: replace all tabs with 4 spaces X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=93c37e5bfd3889c627d0de2bc196306c785875bb;p=scpubgit%2FSystem-Introspector.git replace all tabs with 4 spaces --- diff --git a/bin/system-introspector b/bin/system-introspector index d50bd4f..88e88ae 100755 --- a/bin/system-introspector +++ b/bin/system-introspector @@ -13,8 +13,8 @@ GetOptions( 's|storage=s' => \my $storage_dir, 'a|all' => \my $update_all, 'g|group=s' => \my @update_groups, - 'd|debug' => \my $debug, - 'l|log-level=s' => \my $log_level, + 'd|debug' => \my $debug, + 'l|log-level=s' => \my $log_level, 'h|help' => sub { pod2usage(0) }, ) or pod2usage(2); @@ -30,7 +30,7 @@ die "Requires --all or --group option\n" #command line arguments override the logging configuration #and --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; diff --git a/lib/System/Introspector/Config.pm b/lib/System/Introspector/Config.pm index 5fe04df..81174c8 100644 --- a/lib/System/Introspector/Config.pm +++ b/lib/System/Introspector/Config.pm @@ -18,7 +18,7 @@ sub _build_config { } sub _build_log_level { - return $_[0]->config->{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 6354eae..92ef512 100644 --- a/lib/System/Introspector/Gatherer.pm +++ b/lib/System/Introspector/Gatherer.pm @@ -13,9 +13,9 @@ has introspectors => (is => 'ro', required => 1); #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; + my ($self, $log_level, $context) = @_; + System::Introspector::Logger->init_logging($log_level, $context); + return $self; } sub gather_all { @@ -33,7 +33,7 @@ sub gather_all { my $instance = $moduleName->new($args); log_trace { "Finished constructing '$moduleName'" }; $report{$base} = $instance->gather; - log_trace { "Finished invocation of '$moduleName->gather()'" }; + log_trace { "Finished invocation of '$moduleName->gather()'" }; } log_trace { "gather_all() has completed" }; diff --git a/lib/System/Introspector/Logger.pm b/lib/System/Introspector/Logger.pm index 59fb98f..c39fa59 100644 --- a/lib/System/Introspector/Logger.pm +++ b/lib/System/Introspector/Logger.pm @@ -10,23 +10,23 @@ use Log::Contextual qw( set_logger ); #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; + 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; } diff --git a/lib/System/Introspector/Logger/Output.pm b/lib/System/Introspector/Logger/Output.pm index 5c9b495..897dff5 100644 --- a/lib/System/Introspector/Logger/Output.pm +++ b/lib/System/Introspector/Logger/Output.pm @@ -6,24 +6,24 @@ use Log::Contextual::WarnLogger; use base qw ( Log::Contextual::WarnLogger ); sub set_execution_context { - my ($self, $context_name) = @_; - - die "must specify an execution context name" - unless defined $context_name; - - $self->{_introspector}->{context_name} = $context_name; + my ($self, $context_name) = @_; + + die "must specify an execution context name" + unless defined $context_name; + + $self->{_introspector}->{context_name} = $context_name; } sub _log { - my $self = shift; - my $level = shift; - my $message = join( "\n", @_ ); - my @timedata = localtime; - my $time = sprintf("%0.2i:%0.2i:%0.2i", $timedata[2], $timedata[1], $timedata[0]); - $message .= "\n" unless $message =~ /\n$/; - my $context = $self->{_introspector}->{context_name}; - $context = 'undefined' unless defined $context; - warn "[$level $time] [$context] $message"; + my $self = shift; + my $level = shift; + my $message = join( "\n", @_ ); + my @timedata = localtime; + my $time = sprintf("%0.2i:%0.2i:%0.2i", $timedata[2], $timedata[1], $timedata[0]); + $message .= "\n" unless $message =~ /\n$/; + my $context = $self->{_introspector}->{context_name}; + $context = 'undefined' unless defined $context; + warn "[$level $time] [$context] $message"; } 1; diff --git a/lib/System/Introspector/Probe/DiskUsage.pm b/lib/System/Introspector/Probe/DiskUsage.pm index 90ecccd..d4aa0a9 100644 --- a/lib/System/Introspector/Probe/DiskUsage.pm +++ b/lib/System/Introspector/Probe/DiskUsage.pm @@ -19,7 +19,7 @@ sub gather { my ($self) = @_; log_debug { "Starting to gather disk usage information" }; return transform_exceptions { - log_trace { "Invoking df command" }; + log_trace { "Invoking df command" }; my @lines = lines_from_command ['df', '-aP']; log_trace { "df command has finished executing" }; shift @lines; # header diff --git a/lib/System/Introspector/Probe/FileHandles.pm b/lib/System/Introspector/Probe/FileHandles.pm index fc05e48..bce6b3e 100644 --- a/lib/System/Introspector/Probe/FileHandles.pm +++ b/lib/System/Introspector/Probe/FileHandles.pm @@ -16,7 +16,7 @@ sub gather { my ($self) = @_; log_debug { "Gathering open file information" }; return transform_exceptions { - log_trace { "Invoking lsof" }; + log_trace { "Invoking lsof" }; my @lines = lines_from_command [$self->_lsof_command_call]; log_trace { "lsof has finished executing" }; my @handles; diff --git a/lib/System/Introspector/Probe/Groups.pm b/lib/System/Introspector/Probe/Groups.pm index 11ba9b8..95b5816 100644 --- a/lib/System/Introspector/Probe/Groups.pm +++ b/lib/System/Introspector/Probe/Groups.pm @@ -30,7 +30,7 @@ sub gather { users => $users, }; } - log_trace { "Completed gathering group information" }; + log_trace { "Completed gathering group information" }; return { groups => \%group }; }; } diff --git a/lib/System/Introspector/Probe/LibDirs/Perl.pm b/lib/System/Introspector/Probe/LibDirs/Perl.pm index 7a6f73a..d197b11 100644 --- a/lib/System/Introspector/Probe/LibDirs/Perl.pm +++ b/lib/System/Introspector/Probe/LibDirs/Perl.pm @@ -61,7 +61,7 @@ sub _gather_libdir_info { sub _open_locate_pm_pipe { my ($self, $libdir) = @_; - log_debug { "Executing 'find' to search for Perl module files in '$libdir'" }; + log_debug { "Executing 'find' to search for Perl module files in '$libdir'" }; return handle_from_command sprintf q{find %s -name '*.pm'}, $libdir; } diff --git a/lib/System/Introspector/Probe/Packages/Apt.pm b/lib/System/Introspector/Probe/Packages/Apt.pm index 76e3e6f..c2a0238 100644 --- a/lib/System/Introspector/Probe/Packages/Apt.pm +++ b/lib/System/Introspector/Probe/Packages/Apt.pm @@ -45,7 +45,7 @@ sub gather { }, }; log_trace { "Completed gathering apt based package information" }; - return $retval; + return $retval; } sub _last_apt_update { diff --git a/lib/System/Introspector/Probe/Puppet.pm b/lib/System/Introspector/Probe/Puppet.pm index 7f8f677..900199c 100644 --- a/lib/System/Introspector/Probe/Puppet.pm +++ b/lib/System/Introspector/Probe/Puppet.pm @@ -34,7 +34,7 @@ sub gather { sub _gather_resources { my ($self) = @_; return transform_exceptions { - log_trace { sprintf "Reading contents of resource file '%s'", $self->resources_file }; + log_trace { sprintf "Reading contents of resource file '%s'", $self->resources_file }; my @lines = output_from_file $self->resources_file; chomp @lines; return [ map { @@ -48,7 +48,7 @@ sub _gather_resources { sub _gather_classes { my ($self) = @_; return transform_exceptions { - log_trace { sprintf "Reading contents of classes file '%s'", $self->classes_file }; + log_trace { sprintf "Reading contents of classes file '%s'", $self->classes_file }; my @lines = output_from_file $self->classes_file; chomp @lines; return \@lines; diff --git a/lib/System/Introspector/Probe/Repositories/Git.pm b/lib/System/Introspector/Probe/Repositories/Git.pm index e17ab26..e710ecd 100644 --- a/lib/System/Introspector/Probe/Repositories/Git.pm +++ b/lib/System/Introspector/Probe/Repositories/Git.pm @@ -118,7 +118,7 @@ sub _gather_git_config { sub _open_git_config_pipe { my ($self, $config) = @_; - log_trace { "Invoking 'git config' for file '$config'" }; + log_trace { "Invoking 'git config' for file '$config'" }; return handle_from_command "git config --file $config --list"; } diff --git a/lib/System/Introspector/Probe/ResolvConf.pm b/lib/System/Introspector/Probe/ResolvConf.pm index e69bb1b..228e339 100644 --- a/lib/System/Introspector/Probe/ResolvConf.pm +++ b/lib/System/Introspector/Probe/ResolvConf.pm @@ -19,9 +19,9 @@ sub gather { return { resolv_conf_file => transform_exceptions { my $file = $self->resolv_conf_file; - log_debug { sprintf("Starting to gather host resolver configuration from '$file'") }; - my $buf = scalar output_from_file $file; - log_trace { "Finished reading contents of file" }; + log_debug { sprintf("Starting to gather host resolver configuration from '$file'") }; + my $buf = scalar output_from_file $file; + log_trace { "Finished reading contents of file" }; return { file_name => $file, body => $buf }; }, }; diff --git a/lib/System/Introspector/Probe/Users.pm b/lib/System/Introspector/Probe/Users.pm index e3bfdc0..cec99e9 100644 --- a/lib/System/Introspector/Probe/Users.pm +++ b/lib/System/Introspector/Probe/Users.pm @@ -48,7 +48,7 @@ sub _gather_crontab { log_trace { "Invoking crontab to get info for user '$user'" }; my ($out, $err, $ok) = output_from_command ['crontab', '-u', $user, '-l']; - log_trace { "crontab has finished executing" }; + log_trace { "crontab has finished executing" }; unless ($ok) { return {} if $err =~ m{^no crontab}i; @@ -65,11 +65,11 @@ sub _gather_ssh_keys { log_trace { "Checking ssh keys for user '$user'" }; unless(-d $ssh_dir) { - log_trace { "User has no ssh directory" }; - return { - files => {}, - authorized => { file_name => $ssh_authkeys, body => '' } - } + log_trace { "User has no ssh directory" }; + return { + files => {}, + authorized => { file_name => $ssh_authkeys, body => '' } + } } my %key; for my $item (files_from_dir $ssh_dir) { diff --git a/lib/System/Introspector/Role/Probe.pm b/lib/System/Introspector/Role/Probe.pm index f9d3425..8153bdf 100644 --- a/lib/System/Introspector/Role/Probe.pm +++ b/lib/System/Introspector/Role/Probe.pm @@ -12,15 +12,15 @@ requires 'gather'; #a probe in the future doesn't have explicit logging support at #least there will be some log that the probe has run before gather => sub { - my ($self) = @_; - - log_trace { "gather() invoked on instance of " . ref($self) }; + my ($self) = @_; + + log_trace { "gather() invoked on instance of " . ref($self) }; }; after gather => sub { - my ($self) = @_; - - log_trace { "gather() has completed on instance of " . ref($self) }; + my ($self) = @_; + + log_trace { "gather() has completed on instance of " . ref($self) }; }; 1; \ No newline at end of file diff --git a/lib/System/Introspector/State.pm b/lib/System/Introspector/State.pm index 089b69f..5ce21eb 100644 --- a/lib/System/Introspector/State.pm +++ b/lib/System/Introspector/State.pm @@ -15,8 +15,8 @@ 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'); + my ($self) = @_; + System::Introspector::Logger->init_logging($self->config->log_level, 'controller'); } sub gather { @@ -123,7 +123,7 @@ sub _cleanup { my ($self, $storage, $known_files) = @_; my %known = map { ($_ => 1) } @$known_files; my @files = $storage->find_files('json'); - log_debug { "Cleaning up" }; + log_debug { "Cleaning up" }; for my $file (@files) { next if $known{$file}; log_trace { "Removing $file" }; diff --git a/t/logsetup.pl b/t/logsetup.pl index e46d2cb..43ba184 100644 --- a/t/logsetup.pl +++ b/t/logsetup.pl @@ -16,9 +16,9 @@ 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', 'test', - System::Introspector::Logger::TestOutput->new({ - levels_upto => 'trace' - }), + System::Introspector::Logger::TestOutput->new({ + levels_upto => 'trace' + }), ); 1;