From: J. D. B. <jd...@go...> - 2006-12-05 17:02:54
|
On December 4, 2006, Mike Schilli wrote: > > wrapped, the exception that I wanted to ignore is now getting > > logged. I don't want that. I want it to be completely silent. > > (Failing that, I'd like to log it at a very low level.) >=20 > Hmm, but if you want it to be completely silent, why aren't you simply > resetting those handlers and then putting them back in place afterwards? >=20 > eval { > local $SIG{__WARN__} =3D 'IGNORE'; > local $SIG{__DIE__} =3D 'IGNORE'; > # ... your code > }; This doesn't help in the event that the eval is in a module I installed o= ff of CPAN, which I can't practically modify to add that to the eval block.= (I could modify it, but it'd be wiped out at the next update, leading to = a maintenance nightmare.) In this case I was dealing with evals in both places: my code, and a modu= le. I tried using local and setting the handler to 'DEFAULT', which seemed= to lead to more complex issues, and before I could fully trace through and= find out what was going on I found out about the eval in the module and de= cided this was an untenable situation to try to fix. So I gave up trying t= o do a quick-and-dirty instrumentation of my code by using these handlers, = and instrumented my code more directly. Which is probably a good thing, al= l in all. > Alternatively, you could check if you're inside an eval{} (at some > sublevel) by using code like >=20 > sub burried_in_eval { > my $i; >=20 > while(my ($pack, $file, $line, $sub) =3D caller($i++)) { > return 1 if $sub eq "(eval)"; > } >=20 > return 0; > } >=20 > and act accordingly in your sig handlers. Turns out there's an even easier way to do that. $^S can be checked to s= ee if code is in an eval. Thinking through this yesterday afternoon I fina= lly decided this wasn't a Log4perl issue, but a general Perl issue, because= really I think you'd almost never want those SIG handlers to fire when you= 're in an eval, trying to trap things before they become warnings and error= s. So I asked at use Perl; , and somebody pointed me to that variable. Since I wound up not using those handlers yesterday, it was a little too = late, but I do still have a module called by this program and by others, an= d I'll have to either instrument it as I did the main program, or go back a= nd use the handlers. (I'm thinking about doing both, for good measure.) Looks to me like the FAQ might want to change the text of those signal ha= ndlers to include a check of $^S to decide whether to log or not. And some= body might like to package it all up in a module, which is what I was tryin= g to do yesterday. :) Thanks, jdb |