Skip Menu |

This queue is for tickets about the Net-SIP CPAN distribution.

Report information
The Basics
Id: 122595
Status: resolved
Priority: 0/
Queue: Net-SIP

People
Owner: Nobody in particular
Requestors: richard.carver [...] cloudmont.co.uk
Cc:
AdminCc:

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



Subject: Net::SIP::Leg incorrect debug level for packets
Date: Mon, 24 Jul 2017 11:19:21 +0000
To: "bug-Net-SIP [...] rt.cpan.org" <bug-Net-SIP [...] rt.cpan.org>
From: Richard Carver <richard.carver [...] cloudmont.co.uk>
Net::SIP::Leg outputs the received and delivered packets when the level is 2 or more. It is supposed to output a short version if the level is 2 and a longer version if the level is 3 or more. However this second check uses the global default debug level and not the package-specific debug level to work this out. As a result when debug is initialised as: default=30 and Net::SIP::Leg=2 the entire packet is output when only the summary should be shown. My fix is as follows. I don't understand why I had to put brackets around DEBUG_LEVEL in Leg.pm, but without it didn't subtract the 2: --- Debug.pm.orig 2017-07-24 11:11:58.404793721 +0000 +++ Debug.pm 2017-07-24 11:11:41.096385946 +0000 @@ -6,7 +6,7 @@ use Time::HiRes 'gettimeofday'; use Scalar::Util 'looks_like_number'; use base 'Exporter'; -our @EXPORT = qw( DEBUG DEBUG_DUMP LEAK_TRACK $DEBUG ); +our @EXPORT = qw( DEBUG DEBUG_DUMP DEBUG_LEVEL LEAK_TRACK $DEBUG ); our @EXPORT_OK = qw( debug stacktrace ); @@ -104,6 +104,7 @@ } return $level } +sub DEBUG_LEVEL { __PACKAGE__->level } ################################################################ # set prefix --- Leg.pm.orig 2017-07-24 11:10:02.488062798 +0000 +++ Leg.pm 2017-07-24 11:08:34.278984649 +0000 @@ -429,7 +429,7 @@ $self->{proto}, ip_parts2string($self->{src}), ip_parts2string($dst), - $packet->dump( Net::SIP::Debug->level -2 ) ); + $packet->dump( (DEBUG_LEVEL) -2 ) ); return $self->sendto($packet,$dst,$callback); } @@ -470,7 +470,7 @@ $DEBUG && DEBUG( 2,"received packet on %s from %s:\n%s", sip_sockinfo2uri($self->{proto},@{$self->{src}}{qw(addr port family)}), sip_sockinfo2uri(@{$from}{qw(proto addr port family)}), - $packet->dump( Net::SIP::Debug->level -2 ) + $packet->dump( (DEBUG_LEVEL) - 2 ) ); return ($packet,$from); }
Am Di 25. Jul 2017, 00:53:28, richard.carver@cloudmont.co.uk schrieb: Show quoted text
> Net::SIP::Leg outputs the received and delivered packets when the > level is 2 or more. It is supposed to output a short version if the > level is 2 and a longer version if the level is 3 or more. However > this second check uses the global default debug level and not the > package-specific debug level to work this out.
Thanks for reporting. But I don't think this is the correct way. Net::SIP::Debug->level should take the level specific to the callers package and there is code for this. Contrary to this using __PACKAGE__ inside a new Net::SIP::Debug::DEBUG_LEVEL as you propose will always expanded (at compile time) to 'Net::SIP::Debug' and thus will not provide a package specific level. I think the real problem was actually the bug in Net::SIP::Debug::level you have reported already in RT#122588.
Subject: RE: [rt.cpan.org #122595] Net::SIP::Leg incorrect debug level for packets
Date: Tue, 8 Aug 2017 09:40:06 +0000
To: "bug-Net-SIP [...] rt.cpan.org" <bug-Net-SIP [...] rt.cpan.org>
From: Richard Carver <richard.carver [...] cloudmont.co.uk>
Hi. I had already fixed RT#122588 when I discovered this issue, so I think it's still a problem. I used __PACKAGE__ because that's what the DEBUG sub does, and it seems to evaluate to the package of the caller: sub DEBUG { goto &debug } sub debug { $DEBUG or return; my $level = __PACKAGE__->level || return; Regards, Richard Carver Show quoted text
-----Original Message----- From: Steffen Ullrich via RT [mailto:bug-Net-SIP@rt.cpan.org] Sent: 08 August 2017 08:49 To: Richard Carver <richard.carver@cloudmont.co.uk> Subject: [rt.cpan.org #122595] Net::SIP::Leg incorrect debug level for packets <URL: https://rt.cpan.org/Ticket/Display.html?id=122595 > Am Di 25. Jul 2017, 00:53:28, richard.carver@cloudmont.co.uk schrieb:
> Net::SIP::Leg outputs the received and delivered packets when the > level is 2 or more. It is supposed to output a short version if the > level is 2 and a longer version if the level is 3 or more. However > this second check uses the global default debug level and not the > package-specific debug level to work this out.
Thanks for reporting. But I don't think this is the correct way. Net::SIP::Debug->level should take the level specific to the callers package and there is code for this. Contrary to this using __PACKAGE__ inside a new Net::SIP::Debug::DEBUG_LEVEL as you propose will always expanded (at compile time) to 'Net::SIP::Debug' and thus will not provide a package specific level. I think the real problem was actually the bug in Net::SIP::Debug::level you have reported already in RT#122588.
Am Di 08. Aug 2017, 05:56:32, richard.carver@cloudmont.co.uk schrieb: Show quoted text
> Hi. I had already fixed RT#122588 when I discovered this issue, so I > think it's still a problem. > > I used __PACKAGE__ because that's what the DEBUG sub does, and it > seems to evaluate to the package of the caller:
__PACKAGE__ is expanded at compile time to the current package. __PACKAGE__->level in Net::SIP::Debug was just an lazy way of writing Net::SIP::Debug->level In my opinion the code works as designed as can be seen with the following example: use strict; use warnings; package Net::SIP::A; use Net::SIP::Debug; sub d10 { DEBUG(10,__PACKAGE__) } sub d20 { DEBUG(20,__PACKAGE__) } package Net::SIP::B; use Net::SIP::Debug; sub d10 { DEBUG(10,__PACKAGE__) } sub d20 { DEBUG(20,__PACKAGE__) } package Net::SIP::C; use Net::SIP::Debug; sub d10 { DEBUG(10,__PACKAGE__) } sub d20 { DEBUG(20,__PACKAGE__) } package main; Net::SIP::Debug->level("A=20"); # A: d10,d20 Net::SIP::Debug->level("B=15"); # B: d10 only Net::SIP::Debug->level(10) ; # global and therefore C: d10 only Net::SIP::A->d10(); # shown Net::SIP::A->d20(); # shown Net::SIP::B->d10(); # shown Net::SIP::B->d20(); # not shown (B=15) Net::SIP::C->d10(); # shown Net::SIP::C->d20(); # not shown (global=10)
Subject: RE: [rt.cpan.org #122595] Net::SIP::Leg incorrect debug level for packets
Date: Wed, 15 Nov 2017 16:35:47 +0000
To: "bug-Net-SIP [...] rt.cpan.org" <bug-Net-SIP [...] rt.cpan.org>
From: Richard Carver <richard.carver [...] cloudmont.co.uk>
The example you show works as expected, but in Leg.pm it does something different: $packet->dump( Net::SIP::Debug->level -2 ) ); Net::SIP::Debug->level returns the global debug level, not the debug level of Leg.pm. For example, if my global debug level is 1 but I have configured a level of 20 on Leg.pm then I do not get the packet dump because it passes a value of -1 to dump. With my proposed change it would pass 19 to dump and would output the packet dump as expected. See my modified version of your example: use strict; use warnings; package Net::SIP::A; use Net::SIP::Debug; sub d10 { DEBUG(10,__PACKAGE__ . ":" . Net::SIP::Debug->level) } sub d20 { DEBUG(20,__PACKAGE__) } package Net::SIP::B; use Net::SIP::Debug; sub d10 { DEBUG(10,__PACKAGE__ . ":" . Net::SIP::Debug->level) } sub d20 { DEBUG(20,__PACKAGE__) } package Net::SIP::C; use Net::SIP::Debug; sub d10 { DEBUG(10,__PACKAGE__ . ":" . Net::SIP::Debug->level) } sub d20 { DEBUG(20,__PACKAGE__) } package main; Net::SIP::Debug->level("A=20"); # A: d10,d20 Net::SIP::Debug->level("B=15"); # B: d10 only Net::SIP::Debug->level(10) ; # global and therefore C: d10 only Net::SIP::A->d10(); # shown Net::SIP::A->d20(); # shown Net::SIP::B->d10(); # shown Net::SIP::B->d20(); # not shown (B=15) Net::SIP::C->d10(); # shown Net::SIP::C->d20(); # not shown (global=10) This outputs: 1510763149.2243 DEBUG:<10> Net::SIP::A::d10[7]: Net::SIP::A:10 1510763149.2243 DEBUG:<20> Net::SIP::A::d20[8]: Net::SIP::A 1510763149.2243 DEBUG:<10> Net::SIP::B::d10[12]: Net::SIP::B:10 1510763149.2244 DEBUG:<10> Net::SIP::C::d10[17]: Net::SIP::C:10 If I change the d10 sub with my proposed change of sub d10 { DEBUG(10,__PACKAGE__ . ":" . DEBUG_LEVEL) } I get the following output: 1510763151.8248 DEBUG:<10> Net::SIP::A::d10[7]: Net::SIP::A:20 1510763151.8248 DEBUG:<20> Net::SIP::A::d20[8]: Net::SIP::A 1510763151.8248 DEBUG:<10> Net::SIP::B::d10[12]: Net::SIP::B:15 1510763151.8249 DEBUG:<10> Net::SIP::C::d10[17]: Net::SIP::C:10
Am Mi 15. Nov 2017, 13:09:12, richard.carver@cloudmont.co.uk schrieb: Show quoted text
> The example you show works as expected, but in Leg.pm it does > something different: > $packet->dump( Net::SIP::Debug->level -2 ) ); > ...
Thanks for insisting on the issue. The problem is fixed in commit #2e8f476 by starting to look for a useful caller with caller(0) instead of caller(1).