From: Lebbeous Fogle-Weekley Date: Wed, 14 Nov 2012 19:50:46 +0000 (-0500) Subject: When running methods for clients, send plain warnings to "real" logs X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c8b808c739637ec68f2d8181f73d93f880f55dd6;p=working%2FOpenSRF.git When running methods for clients, send plain warnings to "real" logs Code inside an OpenSRF application method may use Perl libraries that warn and carp like most Perl code is wont to do. Instead of letting those message go to STDERR where they can be easily missed (and take up lots of disk space on application boxes), why not catch them and redirect them to our "real" logs using OpenSRF::Utils::Logger ? Deployment of this change would probably have the side effect of bringing to light bugs in applications (Evergreen) that will suddenly seem very noisy. Signed-off-by: Lebbeous Fogle-Weekley Signed-off-by: Galen Charlton --- diff --git a/src/perl/lib/OpenSRF/Application.pm b/src/perl/lib/OpenSRF/Application.pm index 0a5c188..5ae98bf 100644 --- a/src/perl/lib/OpenSRF/Application.pm +++ b/src/perl/lib/OpenSRF/Application.pm @@ -581,8 +581,16 @@ sub run { if (!$self->{remote}) { my $code = \&{$self->{package} . '::' . $self->{method}}; my $err = undef; + my $warnhandler; try { + $warnhandler = $SIG{__WARN__}; + $SIG{__WARN__} = sub { + (my $msg = shift) =~ s/\n$//; + $log->warn($self->{api_name} . ": $msg"); + return 1; # prevents warning going out to stderr + }; + $resp = $code->($self, $req, @params); } catch Error with { @@ -591,6 +599,8 @@ sub run { if( ref($self) eq 'HASH') { $log->error("Sub $$self{package}::$$self{method} DIED!!!\n\t$err\n", ERROR); } + } finally { + $SIG{__WARN__} = $warnhandler; }; if($err) {