From 94eafa2a9ba34d2cbcd678fff5a0dcbfcfa40e7c Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sun, 26 Jan 2020 19:47:38 +0100 Subject: Less logs but better logs --- ldapserver/client.go | 24 ++++++++++++++++++------ ldapserver/logger.go | 2 ++ ldapserver/route.go | 9 +++++---- 3 files changed, 25 insertions(+), 10 deletions(-) (limited to 'ldapserver') diff --git a/ldapserver/client.go b/ldapserver/client.go index 501af2a..085041f 100644 --- a/ldapserver/client.go +++ b/ldapserver/client.go @@ -134,7 +134,9 @@ func (c *client) serve() { Logger.Printf("Error reading Message : %s\n\t%x", err.Error(), messagePacket.bytes) continue } - Logger.Printf("<<< %d - %s - hex=%x", c.Numero, message.ProtocolOpName(), messagePacket) + if DEBUG { + Logger.Printf("<<< %d - %s - hex=%x", c.Numero, message.ProtocolOpName(), messagePacket) + } // TODO: Use a implementation to limit runnuning request by client // solution 1 : when the buffered output channel is full, send a busy @@ -172,12 +174,16 @@ func (c *client) serve() { // * close client connection // * signal to server that client shutdown is ok func (c *client) close() { - Logger.Printf("client %d close()", c.Numero) + if DEBUG { + Logger.Printf("client %d close()", c.Numero) + } close(c.closing) // stop reading from client c.rwc.SetReadDeadline(time.Now().Add(time.Millisecond)) - Logger.Printf("client %d close() - stop reading from client", c.Numero) + if DEBUG { + Logger.Printf("client %d close() - stop reading from client", c.Numero) + } // signals to all currently running request processor to stop c.mutex.Lock() @@ -186,11 +192,15 @@ func (c *client) close() { go request.Abandon() } c.mutex.Unlock() - Logger.Printf("client %d close() - Abandon signal sent to processors", c.Numero) + if DEBUG { + Logger.Printf("client %d close() - Abandon signal sent to processors", c.Numero) + } c.wg.Wait() // wait for all current running request processor to end close(c.chanOut) // No more message will be sent to client, close chanOUT - Logger.Printf("client [%d] request processors ended", c.Numero) + if DEBUG { + Logger.Printf("client [%d] request processors ended", c.Numero) + } <-c.writeDone // Wait for the last message sent to be written c.rwc.Close() // close client connection @@ -201,7 +211,9 @@ func (c *client) close() { func (c *client) writeMessage(m *ldap.LDAPMessage) { data, _ := m.Write() - Logger.Printf(">>> %d - %s - hex=%x", c.Numero, m.ProtocolOpName(), data.Bytes()) + if DEBUG { + Logger.Printf(">>> %d - %s - hex=%x", c.Numero, m.ProtocolOpName(), data.Bytes()) + } c.bw.Write(data.Bytes()) c.bw.Flush() } diff --git a/ldapserver/logger.go b/ldapserver/logger.go index fdac2f4..70352e3 100644 --- a/ldapserver/logger.go +++ b/ldapserver/logger.go @@ -8,6 +8,8 @@ import ( var Logger logger +const DEBUG = false + // Logger represents log.Logger functions from the standard library type logger interface { Fatal(v ...interface{}) diff --git a/ldapserver/route.go b/ldapserver/route.go index d5bd00a..ec09f7d 100644 --- a/ldapserver/route.go +++ b/ldapserver/route.go @@ -148,10 +148,11 @@ func (h *RouteMux) ServeLDAP(s UserState, w ResponseWriter, r *Message) { } if route.label != "" { - Logger.Printf("") - Logger.Printf(" ROUTE MATCH ; %s", route.label) - Logger.Printf("") - // Logger.Printf(" ROUTE MATCH ; %s", runtime.FuncForPC(reflect.ValueOf(route.handler).Pointer()).Name()) + if DEBUG { + Logger.Printf("") + Logger.Printf(" ROUTE MATCH ; %s", route.label) + Logger.Printf("") + } } route.handler(s, w, r) -- cgit v1.2.3