From 50c56a811bc92ad3b16acf0ff6fc593eb890ae97 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 18 Dec 2015 13:18:12 +0000 Subject: [PATCH] Bug 15253 - Log stderr via Koha::Logger as well By logging stderr to the log file, we can much more easily find and debug errors in the SIP server. Stderr has its own category STDERR so these messages can easily be filtered out of the log if need be. --- C4/SIP/SIPServer.pm | 2 ++ C4/SIP/Trapper.pm | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 C4/SIP/Trapper.pm diff --git a/C4/SIP/SIPServer.pm b/C4/SIP/SIPServer.pm index b5ad02b..a65089d 100755 --- a/C4/SIP/SIPServer.pm +++ b/C4/SIP/SIPServer.pm @@ -18,6 +18,8 @@ use C4::SIP::Sip::Checksum qw(checksum verify_cksum); use C4::SIP::Sip::MsgType qw( handle login_core ); use Koha::Logger; +use C4::SIP::Trapper; +tie *STDERR, "C4::SIP::Trapper"; use base qw(Net::Server::PreFork); diff --git a/C4/SIP/Trapper.pm b/C4/SIP/Trapper.pm new file mode 100644 index 0000000..0a2b872 --- /dev/null +++ b/C4/SIP/Trapper.pm @@ -0,0 +1,21 @@ +package C4::SIP::Trapper; + +use Modern::Perl; + +use Koha::Logger; + +sub TIEHANDLE { + my $class = shift; + bless [], $class; +} + +sub PRINT { + my $self = shift; + $Log::Log4perl::caller_depth++; + my $logger = Koha::Logger->get({ interface => 'sip', category => 'STDERR' }); + warn @_; + $logger->error(@_); + $Log::Log4perl::caller_depth--; +} + +1; -- 2.7.4