Added timestamps to irc.Line and debug output

This commit is contained in:
Graham Lyon 2010-11-20 23:40:45 +00:00 committed by Alex Bramley
parent 83e1f9ca74
commit 8ad6e67467
1 changed files with 5 additions and 3 deletions

View File

@ -56,6 +56,7 @@ type Line struct {
Nick, Ident, Host, Src string Nick, Ident, Host, Src string
Cmd, Text, Raw string Cmd, Text, Raw string
Args []string Args []string
Time *time.Time
} }
// Creates a new IRC connection object, but doesn't connect to anything so // Creates a new IRC connection object, but doesn't connect to anything so
@ -187,7 +188,7 @@ func (conn *Conn) send() {
} }
conn.io.Flush() conn.io.Flush()
if conn.Debug { if conn.Debug {
fmt.Println("-> " + line) fmt.Println(time.UTC().Format("[15:04:05]") + " -> " + line)
} }
} }
} }
@ -196,6 +197,7 @@ func (conn *Conn) send() {
func (conn *Conn) recv() { func (conn *Conn) recv() {
for { for {
s, err := conn.io.ReadString('\n') s, err := conn.io.ReadString('\n')
t := time.UTC()
if err != nil { if err != nil {
conn.error("irc.recv(): %s", err.String()) conn.error("irc.recv(): %s", err.String())
conn.shutdown() conn.shutdown()
@ -203,10 +205,10 @@ func (conn *Conn) recv() {
} }
s = strings.Trim(s, "\r\n") s = strings.Trim(s, "\r\n")
if conn.Debug { if conn.Debug {
fmt.Println("<- " + s) fmt.Println(t.Format("[15:04:05]") + " <- " + s)
} }
line := &Line{Raw: s} line := &Line{Raw: s, Time: t}
if s[0] == ':' { if s[0] == ':' {
// remove a source and parse it // remove a source and parse it
if idx := strings.Index(s, " "); idx != -1 { if idx := strings.Index(s, " "); idx != -1 {