Bugzilla – Attachment 36260 Details for
Bug 13413
Koha::Log - an attempt to have sane logging in Koha
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
bug_13413: use Koha::Log with syslog sink instead of syslog directly in Sipserver.pm
bug13413-use-KohaLog-with-syslog-sink-instead-of-s.patch (text/plain), 7.33 KB, created by
Srdjan Jankovic
on 2015-03-02 01:46:13 UTC
(
hide
)
Description:
bug_13413: use Koha::Log with syslog sink instead of syslog directly in Sipserver.pm
Filename:
MIME Type:
Creator:
Srdjan Jankovic
Created:
2015-03-02 01:46:13 UTC
Size:
7.33 KB
patch
obsolete
>From 0c1ac00786547af26a6a5ce02480e6efb537dd30 Mon Sep 17 00:00:00 2001 >From: Srdjan <srdjan@catalyst.net.nz> >Date: Wed, 29 Oct 2014 12:52:45 +1300 >Subject: [PATCH] bug_13413: use Koha::Log with syslog sink instead of syslog > directly in Sipserver.pm > >This way we can sift out debugs >--- > C4/SIP/SIPServer.pm | 56 +++++++++++++++++++++++++++-------------------------- > 1 file changed, 29 insertions(+), 27 deletions(-) > >diff --git a/C4/SIP/SIPServer.pm b/C4/SIP/SIPServer.pm >index 20a97c6..c5ec0cd 100755 >--- a/C4/SIP/SIPServer.pm >+++ b/C4/SIP/SIPServer.pm >@@ -5,7 +5,6 @@ use strict; > use warnings; > use FindBin qw($Bin); > use lib "$Bin"; >-use Sys::Syslog qw(syslog); > use Net::Server::PreFork; > use IO::Socket::INET; > use Socket qw(:DEFAULT :crlf); >@@ -16,6 +15,7 @@ use C4::SIP::Sip::Configuration; > use C4::SIP::Sip::Checksum qw(checksum verify_cksum); > use C4::SIP::Sip::MsgType qw( handle login_core ); > use C4::SIP::Sip qw( read_SIP_packet ); >+use Koha::Log qw(:log set_default_logger); > > use base qw(Net::Server::PreFork); > >@@ -28,6 +28,11 @@ use constant LOG_SIP => "local6"; # Local alias for the logging facility > # A script with no MAIN namespace? > # A module that takes command line args? > >+set_default_logger( >+ Syslog => {min_level => 'warn', facility => LOG_SIP}, >+ Stdout => {min_level => 'fatal'}, >+); >+ > my %transports = ( > RAW => \&raw_transport, > telnet => \&telnet_transport, >@@ -104,14 +109,13 @@ sub process_request { > $self->{service} = $config->find_service($sockaddr, $port, $proto); > > if (!defined($self->{service})) { >- syslog("LOG_ERR", "process_request: Unknown recognized server connection: %s:%s/%s", $sockaddr, $port, $proto); >- die "process_request: Bad server connection"; >+ log_fatal { "process_request: Unknown recognized server connection: %s:%s/%s", $sockaddr, $port, $proto }; > } > > $transport = $transports{$self->{service}->{transport}}; > > if (!defined($transport)) { >- syslog("LOG_WARNING", "Unknown transport '%s', dropping", $service->{transport}); >+ log_warn { "Unknown transport '%s', dropping", $service->{transport} }; > return; > } else { > &$transport($self); >@@ -129,35 +133,35 @@ sub raw_transport { > > while (!$self->{account}) { > local $SIG{ALRM} = sub { die "raw_transport Timed Out!\n"; }; >- syslog("LOG_DEBUG", "raw_transport: timeout is %d", $service->{timeout}); >+ log_debug { "raw_transport: timeout is %d", $service->{timeout} }; > $input = read_SIP_packet(*STDIN); > if (!$input) { > # EOF on the socket >- syslog("LOG_INFO", "raw_transport: shutting down: EOF during login"); >+ log_info { "raw_transport: shutting down: EOF during login" }; > return; > } > $input =~ s/[\r\n]+$//sm; # Strip off trailing line terminator(s) > last if C4::SIP::Sip::MsgType::handle($input, $self, LOGIN); > } > >- syslog("LOG_DEBUG", "raw_transport: uname/inst: '%s/%s'", >+ log_debug { "raw_transport: uname/inst: '%s/%s'", > $self->{account}->{id}, >- $self->{account}->{institution}); >+ $self->{account}->{institution} }; > > $self->sip_protocol_loop(); >- syslog("LOG_INFO", "raw_transport: shutting down"); >+ log_info { "raw_transport: shutting down" }; > } > > sub get_clean_string { > my $string = shift; > if (defined $string) { >- syslog("LOG_DEBUG", "get_clean_string pre-clean(length %s): %s", length($string), $string); >+ log_debug { "get_clean_string pre-clean(length %s): %s", length($string), $string }; > chomp($string); > $string =~ s/^[^A-z0-9]+//; > $string =~ s/[^A-z0-9]+$//; >- syslog("LOG_DEBUG", "get_clean_string post-clean(length %s): %s", length($string), $string); >+ log_debug { "get_clean_string post-clean(length %s): %s", length($string), $string }; > } else { >- syslog("LOG_INFO", "get_clean_string called on undefined"); >+ log_info { "get_clean_string called on undefined" }; > } > return $string; > } >@@ -167,7 +171,7 @@ sub get_clean_input { > my $in = <STDIN>; > $in = get_clean_string($in); > while (my $extra = <STDIN>){ >- syslog("LOG_ERR", "get_clean_input got extra lines: %s", $extra); >+ log_error { "get_clean_input got extra lines: %s", $extra }; > } > return $in; > } >@@ -180,7 +184,7 @@ sub telnet_transport { > my $input; > my $config = $self->{config}; > my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30; >- syslog("LOG_DEBUG", "telnet_transport: timeout is %s", $timeout); >+ log_debug { "telnet_transport: timeout is %s", $timeout }; > > eval { > local $SIG{ALRM} = sub { die "telnet_transport: Timed Out ($timeout seconds)!\n"; }; >@@ -199,10 +203,10 @@ sub telnet_transport { > $pwd = <STDIN>; > alarm 0; > >- syslog("LOG_DEBUG", "telnet_transport 1: uid length %s, pwd length %s", length($uid), length($pwd)); >+ log_debug { "telnet_transport 1: uid length %s, pwd length %s", length($uid), length($pwd) }; > $uid = get_clean_string ($uid); > $pwd = get_clean_string ($pwd); >- syslog("LOG_DEBUG", "telnet_transport 2: uid length %s, pwd length %s", length($uid), length($pwd)); >+ log_debug { "telnet_transport 2: uid length %s, pwd length %s", length($uid), length($pwd) }; > > if (exists ($config->{accounts}->{$uid}) > && ($pwd eq $config->{accounts}->{$uid}->password())) { >@@ -211,25 +215,23 @@ sub telnet_transport { > last; > } > } >- syslog("LOG_WARNING", "Invalid login attempt: '%s'", ($uid||'')); >+ log_warn { "Invalid login attempt: '%s'", ($uid||'') }; > print("Invalid login$CRLF"); > } > }; # End of eval > > if ($@) { >- syslog("LOG_ERR", "telnet_transport: Login timed out"); >- die "Telnet Login Timed out"; >+ log_fatal { "telnet_transport: Login timed out" }; > } elsif (!defined($account)) { >- syslog("LOG_ERR", "telnet_transport: Login Failed"); >- die "Login Failure"; >+ log_fatal { "telnet_transport: Login Failed" }; > } else { >- print "Login OK. Initiating SIP$CRLF"; >+ print "Login OK. Initiating SIP$CRLF"; > } > > $self->{account} = $account; >- syslog("LOG_DEBUG", "telnet_transport: uname/inst: '%s/%s'", $account->{id}, $account->{institution}); >+ log_debug { "telnet_transport: uname/inst: '%s/%s'", $account->{id}, $account->{institution} }; > $self->sip_protocol_loop(); >- syslog("LOG_INFO", "telnet_transport: shutting down"); >+ log_info { "telnet_transport: shutting down" }; > } > > # >@@ -271,19 +273,19 @@ sub sip_protocol_loop { > $input =~ s/[^A-z0-9]+$//s; # Same on the end, should get DOSsy ^M line-endings too. > while (chomp($input)) {warn "Extra line ending on input";} > unless ($input) { >- syslog("LOG_ERR", "sip_protocol_loop: empty input skipped"); >+ log_error { "sip_protocol_loop: empty input skipped" }; > print("96$CR"); > next; > } > # end cheap input hacks > my $status = handle($input, $self, $expect); > if (!$status) { >- syslog("LOG_ERR", "sip_protocol_loop: failed to handle %s",substr($input,0,2)); >+ log_error { "sip_protocol_loop: failed to handle %s",substr($input,0,2) }; > } > next if $status eq REQUEST_ACS_RESEND; > if ($expect && ($status ne $expect)) { > # We received a non-"RESEND" that wasn't what we were expecting. >- syslog("LOG_ERR", "sip_protocol_loop: expected %s, received %s, exiting", $expect, $input); >+ log_error { "sip_protocol_loop: expected %s, received %s, exiting", $expect, $input }; > } > # We successfully received and processed what we were expecting > $expect = ''; >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13413
:
34188
|
34189
|
34190
|
36259
| 36260 |
36261