From: Tyler Riddle Date: Wed, 7 Nov 2012 02:23:49 +0000 (-0800) Subject: added in file, line, and method info for log invocation X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5987037ede8d03ada7c8ea1af04d9288f0f0ab9a;p=scpubgit%2FObject-Remote.git added in file, line, and method info for log invocation --- diff --git a/lib/Object/Remote/Logging/Logger.pm b/lib/Object/Remote/Logging/Logger.pm index a324848..7c42a58 100644 --- a/lib/Object/Remote/Logging/Logger.pm +++ b/lib/Object/Remote/Logging/Logger.pm @@ -3,7 +3,7 @@ package Object::Remote::Logging::Logger; use Moo; use Scalar::Util qw(weaken); -has format => ( is => 'ro', required => 1, default => sub { '[%l %r] %s' } ); +has format => ( is => 'ro', required => 1, default => sub { '[%l %r] %f:%i %p::%m %s' } ); has level_names => ( is => 'ro', required => 1 ); has min_level => ( is => 'ro', required => 1 ); has max_level => ( is => 'ro' ); @@ -62,7 +62,9 @@ sub _create_format_lookup { return { '%' => '%', t => $self->_render_time($metadata->{timestamp}), r => $self->_render_remote($metadata->{object_remote}), - s => $self->_render_log(@$content), l => $level, p => $metadata->{package}, + s => $self->_render_log(@$content), l => $level, + p => $metadata->{package}, m => $metadata->{method}, + f => $metadata->{filename}, i => $metadata->{line}, }; } diff --git a/lib/Object/Remote/Logging/Router.pm b/lib/Object/Remote/Logging/Router.pm index 14b97ad..ffc51b9 100644 --- a/lib/Object/Remote/Logging/Router.pm +++ b/lib/Object/Remote/Logging/Router.pm @@ -55,9 +55,18 @@ 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}:://; + foreach my $logger ($self->_get_loggers(%metadata)) { $logger->$level([ $generator->(@args) ], \%metadata); }