Skip Menu |
 

This queue is for tickets about the Log-Handler CPAN distribution.

Report information
The Basics
Id: 75596
Status: patched
Priority: 0/
Queue: Log-Handler

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.71
Fixed in: (no value)



Subject: %s placeholder
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 286
Download (untitled) / with headers
text/plain 286b
Currently, with the %s placeholder in message_layout, the subroutine name is always reported as Log::Handler::Levels::__ANON__. Should _get_c_sub in Handler/Pattern.pm be replaced by something like: sub _get_c_sub { (caller(3+$Log::Handler::CALLER_LEVEL))[3]//"" } ? Thanks, David
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-10811-1331085623-1407.75596-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 1004
Download (untitled) / with headers
text/plain 1004b
On Tue Mar 06 20:51:07 2012, http://dr1024.myopenid.com/ wrote: Show quoted text
> Currently, with the %s placeholder in message_layout, the subroutine > name is always reported as Log::Handler::Levels::__ANON__. > > Should _get_c_sub in Handler/Pattern.pm be replaced by something like: > > sub _get_c_sub { (caller(3+$Log::Handler::CALLER_LEVEL))[3]//"" }
No. Log::Handler returns what caller returns. --- use strict; use warnings; use Data::Dumper; sub foo { print Dumper([ caller(0) ]); } my $bar = sub { print Dumper([ caller(0) ]); }; &foo(); &$bar(); --- $VAR1 = [ 'main', 'test.pl', 14, 'main::foo', 1, undef, undef, undef, 1794, 'UUUUUUUUUUU', undef ]; $VAR1 = [ 'main', 'test.pl', 15, 'main::__ANON__', 1, undef, undef, undef, 1794, 'UUUUUUUUUUU', undef ];
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-10811-1331085623-1407.75596-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-10811-1331085623-1407.75596-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-10809-1331090858-272.75596-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 902
Download (untitled) / with headers
text/plain 902b
But -------------------- test-bug.pl use strict; use warnings; use Log::Handler; my $log = Log::Handler->new(); $log->add(screen => { maxlevel => "debug", message_layout => '%f:%l %s %m', }); sub foo { $log->debug("hello from foo"); } foo(); -------------------- outputs: test-bug.pl:14 Log::Handler::Levels::__ANON__ hello from foo Increasing the caller level by 1 inside _get_c_sub makes the %s output more useful. David On Tue Mar 06 21:00:23 2012, BLOONIX wrote: Show quoted text
> On Tue Mar 06 20:51:07 2012, http://dr1024.myopenid.com/ wrote:
> > Currently, with the %s placeholder in message_layout, the subroutine > > name is always reported as Log::Handler::Levels::__ANON__. > > > > Should _get_c_sub in Handler/Pattern.pm be replaced by something like: > > > > sub _get_c_sub { (caller(3+$Log::Handler::CALLER_LEVEL))[3]//"" }
> > No. Log::Handler returns what caller returns.
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-10809-1331090858-272.75596-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-10811-1331085623-1407.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-10809-1331090858-272.75596-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-12231-1331136991-512.75596-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 216
Download (untitled) / with headers
text/plain 216b
Show quoted text
> outputs: > > test-bug.pl:14 Log::Handler::Levels::__ANON__ hello from foo > > Increasing the caller level by 1 inside _get_c_sub makes the %s output > more useful.
Hmm, you could be right. Let me do some tests.
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-12231-1331136991-512.75596-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-10811-1331085623-1407.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-10809-1331090858-272.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-12231-1331136991-512.75596-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-10811-1331137760-1097.75596-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 1593
Download (untitled) / with headers
text/plain 1.5k
Unfortunately that is not possible. Let me explain it: --- use Log::Handler; $Log::Handler::CALLER_LEVEL = 1; my $log = Log::Handler->new(); $log->add(screen => { message_layout => '%m %s', debug_trace => 1 }); $log->warn("foo"); --- Output: Use of uninitialized value in concatenation (.) or string at (eval 8) line 1. foo CALL(2): package(main) filename(test.pl) line(8) subroutine (Log::Handler::Levels::__ANON__) hasargs(1) CALL(1): package(Log::Handler::Levels) filename(/usr/local/share/ perl/5.10.1/Log/Handler/Levels.pm) line(212) subroutine (Log::Handler::Output::log) hasargs(1) wantarray(0) CALL(0): package(Log::Handler::Output) filename(/usr/local/share/ perl/5.10.1/Log/Handler/Output.pm) line(96) subroutine (Log::Handler::Output::_add_trace) hasargs(1) You can see here that just "foo" is printed, but not the subroutine or line number, because caller level 3 does not exists. Next example: --- use Log::Handler; $Log::Handler::CALLER_LEVEL = 1; my $log = Log::Handler->new(); $log->add(screen => { message_layout => '%m %s line %l' }); &foo; sub foo { $log->warn("foo"); $log->warn("bar"); $log->warn("baz"); } --- Output: foo main::foo line 8 bar main::foo line 8 baz main::foo line 8 I don't think that this way of debugging is the right way. We just see every time the same line number. If the package or subroutine is very large then I want to see on which line the logger was called and not which subroutine above called the logger. If you want that, then please set CALLER_LEVEL to 1. $Log::Handler::CALLER_LEVEL = 1; Cheers, Jonny
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-10811-1331137760-1097.75596-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-10811-1331085623-1407.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-10809-1331090858-272.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-12231-1331136991-512.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-10811-1331137760-1097.75596-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-10809-1331137963-1973.75596-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 211
Download (untitled) / with headers
text/plain 211b
I forgot... You can use your own placeholder or overwrite %s if you really want that. my $log = Log::Handler->new(); $log->set_pattern("%s", "subroutine", sub { (caller (3+$Log::Handler::CALLER_LEVEL))[3] });
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-10809-1331137963-1973.75596-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-10811-1331085623-1407.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-10809-1331090858-272.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-12231-1331136991-512.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-10811-1331137760-1097.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-10809-1331137963-1973.75596-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-10812-1331168863-1975.75596-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 605
Download (untitled) / with headers
text/plain 605b
I think both your examples above work ok with the patch I suggested. As you say, calling $log->warn outside any subroutine (as in your first example) would cause an issue with %s, hence catch that case with //"" (as in the patch). Only _get_c_sub needs any change (globally raising CALLER_LEVEL is not the solution). Thanks, David On Wed Mar 07 11:32:43 2012, BLOONIX wrote: Show quoted text
> I forgot... > > You can use your own placeholder or overwrite %s if you really want that. > > my $log = Log::Handler->new(); > $log->set_pattern("%s", "subroutine", sub { (caller > (3+$Log::Handler::CALLER_LEVEL))[3] });
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-10812-1331168863-1975.75596-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-10811-1331085623-1407.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-10809-1331090858-272.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-12231-1331136991-512.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-10811-1331137760-1097.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-10809-1331137963-1973.75596-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-10812-1331168863-1975.75596-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-10815-1331169300-844.75596-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 132
Download (untitled) / with headers
text/plain 132b
Sorry David, but I will not patch _get_c_sub. If you are unlucky with the placeholder %s then please use set_pattern. Cheers Jonny
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-10813-1331187106-1237.75596-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 8
see 0.73


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.