add more logging

This commit is contained in:
Jeremy Latt 2014-02-13 18:59:45 -08:00
parent b6a7d98b64
commit b8bbc7eeb5
3 changed files with 27 additions and 6 deletions

@ -15,6 +15,7 @@ type Client struct {
awayMessage string
channels ChannelSet
conn net.Conn
ctime time.Time
destroyed bool
hostname string
idleTimer *time.Timer
@ -32,9 +33,12 @@ type Client struct {
}
func NewClient(server *Server, conn net.Conn) *Client {
now := time.Now()
client := &Client{
atime: now,
channels: make(ChannelSet),
conn: conn,
ctime: now,
hostname: AddrLookupHostname(conn.RemoteAddr()),
replies: make(chan Reply),
server: server,
@ -136,7 +140,7 @@ func (client *Client) writeConn() {
for reply := range client.replies {
if DEBUG_CLIENT {
log.Printf("%s ← %s %s", client, reply.Source(), reply)
log.Printf("%s ← %s", client, reply)
}
for _, str := range reply.Format(client) {
if DEBUG_NET {
@ -161,6 +165,12 @@ func (client *Client) Destroy() {
return
}
if DEBUG_CLIENT {
log.Printf("%s destroy", client)
}
client.destroyed = true
client.conn.Close()
close(client.replies)
@ -179,11 +189,13 @@ func (client *Client) Destroy() {
client.server.clients.Remove(client)
client.destroyed = true
}
func (client *Client) Reply(replies ...Reply) {
if client.replies == nil {
if client.destroyed {
if DEBUG_CLIENT {
log.Printf("%s.Reply: destroyed", client)
}
return
}
for _, reply := range replies {

@ -1,6 +1,7 @@
package irc
import (
"log"
"net"
"strings"
)
@ -19,9 +20,17 @@ func AddrLookupHostname(addr net.Addr) string {
}
func LookupHostname(addr string) string {
if DEBUG_NET {
log.Printf("LookupHostname(%s)", addr)
}
names, err := net.LookupAddr(addr)
if err != nil {
return addr
}
return strings.TrimSuffix(names[0], ".")
hostname := strings.TrimSuffix(names[0], ".")
if DEBUG_NET {
log.Printf("LookupHostname(%s) → %s", addr, hostname)
}
return hostname
}

@ -52,7 +52,7 @@ func NewServer(config *Config) *Server {
func (server *Server) receiveCommands(commands <-chan Command) {
for command := range commands {
if DEBUG_SERVER {
log.Printf("%s → %s %s", command.Client(), server, command)
log.Printf("%s → %s %+v", command.Client(), server, command)
}
client := command.Client()
@ -65,7 +65,7 @@ func (server *Server) receiveCommands(commands <-chan Command) {
command.HandleServer(server)
if DEBUG_SERVER {
log.Printf("%s → %s %s processed", command.Client(), server, command)
log.Printf("%s → %s %+v processed", command.Client(), server, command)
}
}
}