use System::Introspector::Config;
use System::Introspector::Logger qw( :log );
-log_debug { "$0 started executing" };
-
GetOptions(
'c|config=s' => \my $config_file,
'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,
'h|help' => sub { pod2usage(0) },
) or pod2usage(2);
die "Requires --all or --group option\n"
unless $update_all or @update_groups;
-log_trace { "Completed parsing command line options" };
+#command line arguments override the logging configuration
+#and --log-level overrides -d
+if (defined($debug) && ! defined($log_level)) {
+ $log_level = 'DEBUG';
+}
$config_file = "$storage_dir/main.conf" unless defined $config_file;
-log_debug { "Configuration file: '$config_file'"; };
-
-my $config = System::Introspector::Config->new(
- config_file => $config_file,
-);
+my %config_args = (config_file => $config_file);
+$config_args{log_level} = $log_level if defined $log_level;
-log_trace { "Completed building configuration" };
+my $config = System::Introspector::Config->new(%config_args);
$config->has_group($_) or die "Unknown group '$_'\n"
for @update_groups;
@update_groups = $config->groups
if $update_all;
-
+
my $state = System::Introspector::State->new(
config => $config,
root => $storage_dir,
);
-log_trace { "Completed building introspector state" };
-
-log_info { "Ready to start gathering results" };
$state->gather(@update_groups);
-log_info { "Completed gathering results" };
__END__
Fetch the specified group. Can be used multiple times.
+=head2 -d, --debug
+
+Force the log level to DEBUG unless -l or --log-level is specified
+
+=head2 -l <level>, --log-level <level>
+
+Set the log level to the value specified; this will override -d. Valid levels are
+TRACE DEBUG INFO WARN ERROR FATAL
+
=head2 -h, --help
Display help.
use System::Introspector::Logger qw( :log );
has introspectors => (is => 'ro', required => 1);
+has log_level => ( is => 'ro');
+
+#the gatherer is the entry point on the remote host
+#where logging has not been initialized yet so
+#it must be initialized again before the probe can
+#run
+sub init_logging {
+ System::Introspector::Logger->init_logging($_[1]);
+ return $_[0];
+}
sub gather_all {
my ($self) = @_;
use strictures 1;
-BEGIN { $ENV{SYSTEM_INTROSPECTOR_LOG_UPTO} = "TRACE" unless exists $ENV{SYSTEM_INTROSPECTOR_LOG_UPTO} };
-
package System::Introspector::Logger;
use base qw(Log::Contextual);
use System::Introspector::Logger::Output;
use Log::Contextual qw( set_logger );
-sub arg_default_logger { $_[1] || System::Introspector::Logger::Output->new({
- env_prefix => 'SYSTEM_INTROSPECTOR_LOG',
-}) };
+sub init_logging {
+ my ($self, $level) = @_;
+
+ $level = 'WARN' unless defined $level;
+
+ #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',
+ }));
+}
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);
+}
+
sub gather {
my ($self, @groups) = @_;
log_debug { "Starting to gather results" };
host => $arg{host},
sudo_user => $arg{sudo} && $self->sudo_user,
introspectors => $arg{introspectors},
- );
+ )->init_logging($self->config->log_level);
}
1;