use Try::Tiny;
use System::Introspector::Report::Source;
use System::Introspector::Report::Config;
+use Log::Contextual qw( set_logger );
+use Log::Contextual::SimpleLogger;
GetOptions(
's|storage=s' => \my $storage_dir,
'r|report=s' => \my @report_types,
'p|publish=s' => \my @publish_types,
'a|all' => \my $all_reports,
+ 'v|verbose+' => \my $log_verbose,
'h|help' => sub { pod2usage(0) },
) or pod2usage(2);
die "$0 requires --config (-c) to be specified\n"
unless defined $config_file;
+my @additional_log_levels = qw( debug trace );
+my $logger = Log::Contextual::SimpleLogger->new({
+ levels => [
+ qw( error fatal info ),
+ grep { defined }
+ @additional_log_levels[0 .. (($log_verbose || 0) - 1)],
+ ],
+});
+set_logger $logger;
+
my $config = System::Introspector::Report::Config
->new(config_file => $config_file);
package System::Introspector::Report::Publish::MediaWiki;
use Moo;
use Try::Tiny;
+use Log::Contextual qw( :log );
use aliased 'System::Introspector::Report::Publish::MediaWiki::Connection';
has page_options => (
sub publish {
my ($self, $reports) = @_;
my $pages = $self->page_options;
- printf "Pushing reports to MediaWiki at '%s'\n", $self->api_uri;
+ log_info { "Pushing reports to MediaWiki at '%s'", $self->api_uri };
for my $page (sort keys %$pages) {
$self->_publish_page($reports, $page, $pages->{$page});
}
- print "Finished pushing to MediaWiki\n";
+ log_info { "Finished pushing to MediaWiki" };
return 1;
}
}
my $sorted = $self->_sort_reports($reports, $options->{report} || []);
unless (scalar @$sorted) {
- print "Skipping page '$page_name': No reports to publish\n";
+ log_debug { "Skipping page '$page_name': No reports to publish" };
return 1;
}
- print "Updating page '$page_name'\n";
+ log_debug { "Updating page '$page_name'" };
my $do_create = $options->{create};
return try {
my $page = $self->get_page($page_name);
if ($page->is_new and not $do_create) {
- print "Skipping page '$page_name': Does not yet exist\n";
+ log_debug { "Skipping page '$page_name': Does not yet exist" };
return 1;
}
my $is_changed = $page->update($sorted);
unless ($is_changed) {
- print "Not pushing page '$page_name': No changes\n";
+ log_Debug { "Not pushing page '$page_name': No changes" };
return 1;
}
$self->put_page($page);
return 1;
}
catch {
- print "Error during page update: $_\n";
+ log_error { "Error during page update: $_" };
return 1;
};
}