X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FObject%2FRemote%2FLogging%2FRouter.pm;h=2d48ca51bdfaff42ce35c84d4ec5de6bc1d7f530;hb=fe203cb2d2fd85b7051a55ffbb34c1b9ac1a65a2;hp=ee403775d4b7b69446db80702b39628974003be4;hpb=b43174a123aae89a1d3666ffd4d7b9d11ad4846c;p=scpubgit%2FObject-Remote.git diff --git a/lib/Object/Remote/Logging/Router.pm b/lib/Object/Remote/Logging/Router.pm index ee40377..2d48ca5 100644 --- a/lib/Object/Remote/Logging/Router.pm +++ b/lib/Object/Remote/Logging/Router.pm @@ -2,6 +2,7 @@ package Object::Remote::Logging::Router; use Moo; use Scalar::Util qw(weaken); +use Sys::Hostname; with 'Log::Contextual::Role::Router'; with 'Object::Remote::Role::LogForwarder'; @@ -46,6 +47,18 @@ sub _get_loggers { return @loggers; } +sub _invoke_logger { + my ($self, $logger, $level_name, $content, $metadata) = @_; + #Invoking the logger like this gets all available data to the + #logging object with out losing any information from the structure. + #This is not a backwards compatible way to invoke the loggers + #but it enables a lot of flexibility in the logger. + #The l-c router could have this method invoke the logger in + #a backwards compatible way and router sub classes invoke + #it in non-backwards compatible ways if desired + $logger->$level_name($content, $metadata); +} + sub handle_log_request { my ($self, $metadata_in, $generator, @args) = @_; my %metadata = %{$metadata_in}; @@ -59,6 +72,8 @@ sub handle_log_request { my $caller_level = delete $metadata{caller_level}; $metadata{object_remote} = $self->_remote_metadata; $metadata{timestamp} = time; + $metadata{pid} = $$; + $metadata{hostname} = hostname; my @caller_info = caller($caller_level); $metadata{filename} = $caller_info[1]; @@ -67,14 +82,14 @@ sub handle_log_request { @caller_info = caller($caller_level + 1); $metadata{method} = $caller_info[3]; $metadata{method} =~ s/^${package}::// if defined $metadata{method}; - + foreach my $logger ($self->_get_loggers(%metadata)) { - $logger->$level([ $generator->(@args) ], \%metadata); + $self->_invoke_logger($logger, $level, [ $generator->(@args) ], \%metadata); } } sub connect { - my ($self, $destination) = @_; + my ($self, $destination, $is_weak) = @_; my $wrapped; if (ref($destination) ne 'CODE') { @@ -84,7 +99,7 @@ sub connect { } push(@{$self->_connections}, $wrapped); - weaken($self->_connections->[-1]); + weaken($self->_connections->[-1]) if $is_weak; } sub _clean_connections {