From bd4afe7e5024b11510f5ab2ea50092eaabc9dcee Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 29 Aug 2015 15:31:00 +0200 Subject: [PATCH] emit only useful log meesates to STDOUT and hide all debuging messages without DEBUG enviroment variable --- bin/ldap-koha.pl | 10 ++++++++++ lib/LDAP/Koha.pm | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bin/ldap-koha.pl b/bin/ldap-koha.pl index e9ed1f9..30c2c9e 100755 --- a/bin/ldap-koha.pl +++ b/bin/ldap-koha.pl @@ -8,6 +8,16 @@ use IO::Socket; use lib 'lib'; use LDAP::Koha; +my $debug = $ENV{DEBUG} || 0; + +BEGIN { + $SIG{'__WARN__'} = sub { + my $level = $1 if $_[0] =~ m/^(#+)/; + return if defined($level) && length($level) > $debug; + + warn join("\n", @_); + }; +} my $listen = shift @ARGV || 'localhost:2389'; my $sock = IO::Socket::INET->new( diff --git a/lib/LDAP/Koha.pm b/lib/LDAP/Koha.pm index 563c968..7415278 100644 --- a/lib/LDAP/Koha.pm +++ b/lib/LDAP/Koha.pm @@ -64,7 +64,7 @@ use constant RESULT_OK => { sub new { my ($class, $sock) = @_; my $self = $class->SUPER::new($sock); - print "connection from: ", $sock->peerhost(), "\n"; + warn "# connection from: ", $sock->peerhost(); return $self; } @@ -146,7 +146,6 @@ sub _dn_attributes { sub search { my $self = shift; my $reqData = shift; - print "searching...\n"; warn "# " . localtime() . " request = ", dump($reqData); @@ -211,6 +210,9 @@ sub search { $sth->execute( @values ); warn "# ", $sth->rows, " results for ",dump( $reqData->{'filter'} ); + my $dump = dump( $reqData->{'filter'} ); + $dump =~ s/[\r\n\s]+/ /gm; + print $sth->rows, " results for $dump\n"; my $last_dn = '?'; my $entry; -- 2.20.1