X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FLogging%2FRouter.pm;h=838da82c74b16e48a193adc363b8be7216fc5a63;hp=14b97add48fb1abbc124098987d7a783faef8890;hb=49dbc3845d98d4e11314b02b75f9fb651aa7b028;hpb=f4a8508058f7bad5052775a8df3e683527c73333 diff --git a/lib/Object/Remote/Logging/Router.pm b/lib/Object/Remote/Logging/Router.pm index 14b97ad..838da82 100644 --- a/lib/Object/Remote/Logging/Router.pm +++ b/lib/Object/Remote/Logging/Router.pm @@ -1,6 +1,7 @@ package Object::Remote::Logging::Router; use Moo; +use Scalar::Util qw(weaken); with 'Log::Contextual::Role::Router'; with 'Object::Remote::Role::LogForwarder'; @@ -55,16 +56,25 @@ sub handle_log_request { #caller_level is useless when log forwarding is in place #so we won't tempt people with using it for now - access #to caller level will be available in the future - delete $metadata{caller_level}; + my $caller_level = delete $metadata{caller_level}; $metadata{object_remote} = $self->_remote_metadata; $metadata{timestamp} = time; + + my @caller_info = caller($caller_level); + $metadata{filename} = $caller_info[1]; + $metadata{line} = $caller_info[2]; + + @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); } } sub connect { - my ($self, $destination) = @_; + my ($self, $destination, $is_weak) = @_; my $wrapped; if (ref($destination) ne 'CODE') { @@ -74,6 +84,7 @@ sub connect { } push(@{$self->_connections}, $wrapped); + weaken($self->_connections->[-1]) if $is_weak; } sub _clean_connections {