3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-26 05:49:25 +01:00

sanify debug net logging

This commit is contained in:
Jeremy Latt 2014-02-12 21:18:02 -08:00
parent 415ccc7607
commit ca25828804

View File

@ -84,11 +84,16 @@ func (c *Client) readConn() {
for { for {
line, err := c.recv.ReadString('\n') line, err := c.recv.ReadString('\n')
if err != nil { if err != nil {
if err != io.EOF { if DEBUG_NET {
log.Printf("%s → %s error: %s", c.conn.RemoteAddr(), c.conn.LocalAddr(), err) if err == io.EOF {
log.Printf("%s → %s closed", c.conn.RemoteAddr(), c.conn.LocalAddr())
} else {
log.Printf("%s → %s error: %s", c.conn.RemoteAddr(), c.conn.LocalAddr(), err)
}
} }
break break
} }
line = strings.TrimSpace(line) line = strings.TrimSpace(line)
if DEBUG_NET { if DEBUG_NET {
log.Printf("%s → %s %s", c.conn.RemoteAddr(), c.conn.LocalAddr(), line) log.Printf("%s → %s %s", c.conn.RemoteAddr(), c.conn.LocalAddr(), line)
@ -96,9 +101,10 @@ func (c *Client) readConn() {
m, err := ParseCommand(line) m, err := ParseCommand(line)
if err != nil { if err != nil {
if err == NotEnoughArgsError { switch err {
case NotEnoughArgsError:
c.Reply(ErrNeedMoreParams(c.server, line)) c.Reply(ErrNeedMoreParams(c.server, line))
} else { default:
c.Reply(ErrUnknownCommand(c.server, line)) c.Reply(ErrUnknownCommand(c.server, line))
} }
continue continue
@ -112,8 +118,12 @@ func (c *Client) readConn() {
func (client *Client) maybeLogWriteError(err error) bool { func (client *Client) maybeLogWriteError(err error) bool {
if err != nil { if err != nil {
if err != io.EOF { if DEBUG_NET {
log.Printf("%s ← %s error: %s", client.conn.RemoteAddr(), client.conn.LocalAddr(), err) if err == io.EOF {
log.Printf("%s ← %s closed", client.conn.RemoteAddr(), client.conn.LocalAddr())
} else {
log.Printf("%s ← %s error: %s", client.conn.RemoteAddr(), client.conn.LocalAddr(), err)
}
} }
return true return true
} }