From: Tyler Riddle Date: Sat, 10 Nov 2012 21:23:15 +0000 (-0800) Subject: convert anything that logged to o-r logging; add new log messages; tweak existing... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=723c1c685aa870149c1dda79fd418e117aa1e6cd;p=scpubgit%2FSystem-Introspector-Report.git convert anything that logged to o-r logging; add new log messages; tweak existing log levels --- diff --git a/lib/System/Introspector/Report/Publish/MediaWiki.pm b/lib/System/Introspector/Report/Publish/MediaWiki.pm index b5ba003..65e9f01 100644 --- a/lib/System/Introspector/Report/Publish/MediaWiki.pm +++ b/lib/System/Introspector/Report/Publish/MediaWiki.pm @@ -3,12 +3,7 @@ use Moo; use Try::Tiny; use Object::Remote; use Object::Remote::Future; -use Log::Contextual::WarnLogger; -use Log::Contextual qw( :log ), - -default_logger => Log::Contextual::WarnLogger->new({ - env_prefix => 'SI_REPORT_MEDIAWIKI', - levels => [qw( error warn info debug trace )], - }); +use System::Introspector::Report::Logging qw( :log ); use aliased 'System::Introspector::Report::Publish::MediaWiki::Updater'; @@ -47,11 +42,13 @@ sub publish { sprintf "Pushing reports to MediaWiki at '%s'", $self->api_uri; }; for my $page (sort keys %$pages) { + log_verbose { "Publishing $page" }; my $options = $pages->{$page}; if ($page =~ m{\%\(meta:(.+?)\)}) { $self->_publish_dynamic($reports, $page, $1, $options); } else { + log_trace { "Standard page: $page" }; $self->_publish_pages([$reports, $page, $options]); } } @@ -61,6 +58,7 @@ sub publish { sub _publish_pages { my ($self, @pages) = @_; + log_trace { sprintf "Publishing %i pages", scalar(@pages) }; my $stream = sub { my $next = shift @pages or return undef; @@ -69,12 +67,16 @@ sub _publish_pages { return [$page_name, $options, $sorted]; }; await_all map { + log_trace { + sprintf "Creating process to handle %i items from the update pool", + scalar(@{ $self->updater_pool }) }; $_->start::process($stream); } @{ $self->updater_pool }; } sub _sort_reports { my ($self, $reports, $included) = @_; + log_trace { "Sorting reports" }; my @matchers = map { $self->_prepare_matcher_from($_); } ref($included) ? @{$included} : $included; @@ -92,6 +94,7 @@ sub _sort_reports { sub _publish_dynamic { my ($self, $reports, $page_name, $key, $options) = @_; + log_debug { "Creating pages for dynamic page '$page_name'" }; my %reports_by_key; for my $report (@$reports) { my $value = $report->{meta}{$key}; @@ -105,6 +108,10 @@ sub _publish_dynamic { my $assoc = $reports_by_key{$value}; push @pages, [$assoc, $effective_page, $options]; } + log_trace { + sprintf "%i pages were created for '%s'; publishing them", + scalar(@pages), $page_name + }; $self->_publish_pages(@pages); return 1; } diff --git a/lib/System/Introspector/Report/Publish/MediaWiki/Updater.pm b/lib/System/Introspector/Report/Publish/MediaWiki/Updater.pm index ff5f61f..109e528 100644 --- a/lib/System/Introspector/Report/Publish/MediaWiki/Updater.pm +++ b/lib/System/Introspector/Report/Publish/MediaWiki/Updater.pm @@ -2,12 +2,7 @@ package System::Introspector::Report::Publish::MediaWiki::Updater; use Moo; use Try::Tiny; use Module::Runtime qw( use_module ); -use Log::Contextual::WarnLogger; -use Log::Contextual qw( :log ), - -default_logger => Log::Contextual::WarnLogger->new({ - env_prefix => 'SI_REPORT_MEDIAWIKI_UPDATER', - levels => [qw( error warn info debug trace )], - }); +use System::Introspector::Report::Logging qw( :log ); has connection => (is => 'ro', lazy => 1, builder => 1, handles => { get_page => 'get', @@ -30,7 +25,9 @@ sub _build_connection { sub process { my ($self, $stream) = @_; + log_debug { "Updater is starting to process individual pages" }; while (my $report = $stream->()) { + log_trace { "Processing page" }; $self->_process_page(@$report); } return 1; @@ -39,22 +36,22 @@ sub process { sub _process_page { my ($self, $page_name, $options, $reports) = @_; unless (scalar @$reports) { - log_debug { "Skipping page '$page_name': No reports to publish" }; + log_verbose { "Skipping page '$page_name': No reports to publish" }; return 1; } my $do_create = $options->{create}; return try { my $page = $self->get_page($page_name); if ($page->is_new and not $do_create) { - log_trace { "Skipping page '$page_name': Does not yet exist" }; + log_verbose { "Skipping page '$page_name': Does not yet exist" }; return 1; } my $is_changed = $page->update($reports); unless ($is_changed) { - log_debug { "Not pushing page '$page_name': No changes" }; + log_verbose { "Not pushing page '$page_name': No changes" }; return 1; } - log_debug { "Updating page '$page_name'" }; + log_info { "Updating page '$page_name'" }; $self->put_page($page); return 1; } diff --git a/lib/System/Introspector/Report/Source.pm b/lib/System/Introspector/Report/Source.pm index ea988b1..0ec6501 100644 --- a/lib/System/Introspector/Report/Source.pm +++ b/lib/System/Introspector/Report/Source.pm @@ -3,12 +3,7 @@ use Moo; use JSON::PP; use IO::All; use Module::Runtime qw( use_module ); -use Log::Contextual::WarnLogger; -use Log::Contextual qw( :log ), - -default_logger => Log::Contextual::WarnLogger->new({ - env_prefix => 'SI_REPORT_SOURCE', - levels => [qw( error warn info debug trace )], - }); +use System::Introspector::Report::Logging qw( :log :dlog ); my $_json = JSON::PP->new->utf8->relaxed->allow_nonref; @@ -33,9 +28,10 @@ sub generate { my @dirs = $self->_find_source_dirs; for my $dir_spec (@dirs) { my ($id, $path) = @$dir_spec; + log_debug { "Starting to load dataset for node '$id' from '$path' " }; my $data = $self->_load_dataset($path, $required) or next; - log_trace { "loading node '$id' from '$path'" }; + log_verbose { "Collecting data from node '$id'" }; $_->collect_from($id, $data) for @generators; } @@ -64,7 +60,7 @@ sub _load_dataset { sub _find_source_dirs { my ($self) = @_; my $root = $self->root; - return map { + return Dlog_trace { "Discovered source dirs: $_" } map { (my $id = $_) =~ s{^\Q$root\E/*}{}; [$id, $_]; } io($root)->all_dirs;