emit only useful log meesates to STDOUT
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 29 Aug 2015 13:31:00 +0000 (15:31 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 29 Aug 2015 13:31:00 +0000 (15:31 +0200)
and hide all debuging messages without DEBUG enviroment variable

bin/ldap-koha.pl
lib/LDAP/Koha.pm

index e9ed1f9..30c2c9e 100755 (executable)
@@ -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(
index 563c968..7415278 100644 (file)
@@ -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;