'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);
#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;
}
sub _build_log_level {
- return $_[0]->config->{log_level};
+ return $_[0]->config->{log_level};
}
sub sudo_user { $_[0]->config->{sudo_user} }
#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 {
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" };
#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;
}
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;
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
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;
users => $users,
};
}
- log_trace { "Completed gathering group information" };
+ log_trace { "Completed gathering group information" };
return { groups => \%group };
};
}
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;
}
},
};
log_trace { "Completed gathering apt based package information" };
- return $retval;
+ return $retval;
}
sub _last_apt_update {
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 {
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;
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";
}
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 };
},
};
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;
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) {
#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
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 {
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" };
#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;