From 2cbbdd6d7e6649bcdb48ae55cb53114ecb40c3f2 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Thu, 26 Sep 2013 10:17:52 +0200 Subject: [PATCH] Remove golog --- client/connection.go | 19 +------------------ client/connection_test.go | 2 -- client/dispatch.go | 5 ++--- client/state_handlers.go | 28 ---------------------------- state/channel.go | 22 ---------------------- state/nick.go | 7 ------- state/tracker.go | 37 ------------------------------------- state/tracker_test.go | 7 ------- 8 files changed, 3 insertions(+), 124 deletions(-) diff --git a/client/connection.go b/client/connection.go index d988a4e..f151daf 100644 --- a/client/connection.go +++ b/client/connection.go @@ -5,8 +5,6 @@ import ( "crypto/tls" "fmt" "github.com/fluffle/goirc/state" - "github.com/fluffle/golog/logging" - "io" "net" "strings" "sync" @@ -107,9 +105,8 @@ func SimpleClient(nick string, args ...string) *Conn { } func Client(cfg *Config) *Conn { - logging.InitFromFlags() if cfg == nil || cfg.Me == nil || cfg.Me.Nick == "" || cfg.Me.Ident == "" { - logging.Fatal("irc.Client(): Both cfg.Nick and cfg.Ident must be non-empty.") + panic("irc.Client(): Both cfg.Nick and cfg.Ident must be non-empty.") } conn := &Conn{ cfg: cfg, @@ -196,7 +193,6 @@ func (conn *Conn) Connect() error { if !hasPort(conn.cfg.Server) { conn.cfg.Server += ":6697" } - logging.Info("irc.Connect(): Connecting to %s with SSL.", conn.cfg.Server) if s, err := tls.Dial("tcp", conn.cfg.Server, conn.cfg.SSLConfig); err == nil { conn.sock = s } else { @@ -206,7 +202,6 @@ func (conn *Conn) Connect() error { if !hasPort(conn.cfg.Server) { conn.cfg.Server += ":6667" } - logging.Info("irc.Connect(): Connecting to %s without SSL.", conn.cfg.Server) if s, err := net.Dial("tcp", conn.cfg.Server); err == nil { conn.sock = s } else { @@ -257,20 +252,14 @@ func (conn *Conn) recv() { for { s, err := conn.io.ReadString('\n') if err != nil { - if err != io.EOF { - logging.Error("irc.recv(): %s", err.Error()) - } conn.shutdown() return } s = strings.Trim(s, "\r\n") - logging.Debug("<- %s", s) if line := parseLine(s); line != nil { line.Time = time.Now() conn.in <- line - } else { - logging.Warn("irc.recv(): problems parsing line:\n %s", s) } } } @@ -309,23 +298,18 @@ func (conn *Conn) write(line string) { if !conn.cfg.Flood { if t := conn.rateLimit(len(line)); t != 0 { // sleep for the current line's time value before sending it - logging.Debug("irc.rateLimit(): Flood! Sleeping for %.2f secs.", - t.Seconds()) <-time.After(t) } } if _, err := conn.io.WriteString(line + "\r\n"); err != nil { - logging.Error("irc.send(): %s", err.Error()) conn.shutdown() return } if err := conn.io.Flush(); err != nil { - logging.Error("irc.send(): %s", err.Error()) conn.shutdown() return } - logging.Debug("-> %s", line) } // Implement Hybrid's flood control algorithm to rate-limit outgoing lines. @@ -355,7 +339,6 @@ func (conn *Conn) shutdown() { if !conn.connected { return } - logging.Info("irc.shutdown(): Disconnected from server.") conn.dispatch(&Line{Cmd: DISCONNECTED}) conn.connected = false conn.sock.Close() diff --git a/client/connection_test.go b/client/connection_test.go index 832b6b0..03f6102 100644 --- a/client/connection_test.go +++ b/client/connection_test.go @@ -3,7 +3,6 @@ package client import ( "code.google.com/p/gomock/gomock" "github.com/fluffle/goirc/state" - "github.com/fluffle/golog/logging" "strings" "testing" "time" @@ -22,7 +21,6 @@ func setUp(t *testing.T, start ...bool) (*Conn, *testState) { st := state.NewMockTracker(ctrl) nc := MockNetConn(t) c := SimpleClient("test", "test", "Testing IRC") - logging.SetLogLevel(logging.LogFatal) c.st = st c.sock = nc diff --git a/client/dispatch.go b/client/dispatch.go index 1af35fb..cc937bc 100644 --- a/client/dispatch.go +++ b/client/dispatch.go @@ -1,7 +1,7 @@ package client import ( - "github.com/fluffle/golog/logging" + "log" "runtime" "strings" "sync" @@ -92,7 +92,6 @@ func (hs *hSet) remove(hn *hNode) { defer hs.Unlock() l, ok := hs.set[hn.event] if !ok { - logging.Error("Removing node for unknown event '%s'", hn.event) return } if hn.next == nil { @@ -147,6 +146,6 @@ func (conn *Conn) dispatch(line *Line) { func (conn *Conn) LogPanic(line *Line) { if err := recover(); err != nil { _, f, l, _ := runtime.Caller(2) - logging.Error("%s:%d: panic: %v", f, l, err) + log.Printf("%s:%d: panic: %v", f, l, err) } } diff --git a/client/state_handlers.go b/client/state_handlers.go index 7a21e9a..e1dee13 100644 --- a/client/state_handlers.go +++ b/client/state_handlers.go @@ -4,7 +4,6 @@ package client // to manage tracking state for an IRC connection import ( - "github.com/fluffle/golog/logging" "strings" ) @@ -51,8 +50,6 @@ func (conn *Conn) h_JOIN(line *Line) { // first we've seen of this channel, so should be us joining it // NOTE this will also take care of nk == nil && ch == nil if nk != conn.cfg.Me { - logging.Warn("irc.JOIN(): JOIN to unknown channel %s received "+ - "from (non-me) nick %s", line.Args[0], line.Nick) return } ch = conn.st.NewChannel(line.Args[0]) @@ -103,14 +100,9 @@ func (conn *Conn) h_MODE(line *Line) { } else if nk := conn.st.GetNick(line.Args[0]); nk != nil { // nick mode change, should be us if nk != conn.cfg.Me { - logging.Warn("irc.MODE(): recieved MODE %s for (non-me) nick %s", - line.Args[1], line.Args[0]) return } nk.ParseModes(line.Args[1]) - } else { - logging.Warn("irc.MODE(): not sure what to do with MODE %s", - strings.Join(line.Args, " ")) } } @@ -118,9 +110,6 @@ func (conn *Conn) h_MODE(line *Line) { func (conn *Conn) h_TOPIC(line *Line) { if ch := conn.st.GetChannel(line.Args[0]); ch != nil { ch.Topic = line.Args[1] - } else { - logging.Warn("irc.TOPIC(): topic change on unknown channel %s", - line.Args[0]) } } @@ -130,9 +119,6 @@ func (conn *Conn) h_311(line *Line) { nk.Ident = line.Args[2] nk.Host = line.Args[3] nk.Name = line.Args[5] - } else { - logging.Warn("irc.311(): received WHOIS info for unknown nick %s", - line.Args[1]) } } @@ -140,9 +126,6 @@ func (conn *Conn) h_311(line *Line) { func (conn *Conn) h_324(line *Line) { if ch := conn.st.GetChannel(line.Args[1]); ch != nil { ch.ParseModes(line.Args[2], line.Args[3:]...) - } else { - logging.Warn("irc.324(): received MODE settings for unknown channel %s", - line.Args[1]) } } @@ -150,9 +133,6 @@ func (conn *Conn) h_324(line *Line) { func (conn *Conn) h_332(line *Line) { if ch := conn.st.GetChannel(line.Args[1]); ch != nil { ch.Topic = line.Args[2] - } else { - logging.Warn("irc.332(): received TOPIC value for unknown channel %s", - line.Args[1]) } } @@ -160,8 +140,6 @@ func (conn *Conn) h_332(line *Line) { func (conn *Conn) h_352(line *Line) { nk := conn.st.GetNick(line.Args[5]) if nk == nil { - logging.Warn("irc.352(): received WHO reply for unknown nick %s", - line.Args[5]) return } if nk == conn.Me() { @@ -220,9 +198,6 @@ func (conn *Conn) h_353(line *Line) { } } } - } else { - logging.Warn("irc.353(): received NAMES list for unknown channel %s", - line.Args[2]) } } @@ -230,8 +205,5 @@ func (conn *Conn) h_353(line *Line) { func (conn *Conn) h_671(line *Line) { if nk := conn.st.GetNick(line.Args[1]); nk != nil { nk.Modes.SSL = true - } else { - logging.Warn("irc.671(): received WHOIS SSL info for unknown nick %s", - line.Args[1]) } } diff --git a/state/channel.go b/state/channel.go index 5067348..de15e1f 100644 --- a/state/channel.go +++ b/state/channel.go @@ -2,7 +2,6 @@ package state import ( "fmt" - "github.com/fluffle/golog/logging" "reflect" "strconv" ) @@ -121,8 +120,6 @@ func (ch *Channel) addNick(nk *Nick, cp *ChanPrivs) { if _, ok := ch.nicks[nk]; !ok { ch.nicks[nk] = cp ch.lookup[nk.Nick] = nk - } else { - logging.Warn("Channel.addNick(): %s already on %s.", nk.Nick, ch.Name) } } @@ -131,23 +128,18 @@ func (ch *Channel) delNick(nk *Nick) { if _, ok := ch.nicks[nk]; ok { delete(ch.nicks, nk) delete(ch.lookup, nk.Nick) - } else { - logging.Warn("Channel.delNick(): %s not on %s.", nk.Nick, ch.Name) } } // Parses mode strings for a channel. func (ch *Channel) ParseModes(modes string, modeargs ...string) { var modeop bool // true => add mode, false => remove mode - var modestr string for i := 0; i < len(modes); i++ { switch m := modes[i]; m { case '+': modeop = true - modestr = string(m) case '-': modeop = false - modestr = string(m) case 'i': ch.Modes.InviteOnly = modeop case 'm': @@ -173,9 +165,6 @@ func (ch *Channel) ParseModes(modes string, modeargs ...string) { ch.Modes.Key, modeargs = modeargs[0], modeargs[1:] } else if !modeop { ch.Modes.Key = "" - } else { - logging.Warn("Channel.ParseModes(): not enough arguments to "+ - "process MODE %s %s%c", ch.Name, modestr, m) } case 'l': if modeop && len(modeargs) != 0 { @@ -183,9 +172,6 @@ func (ch *Channel) ParseModes(modes string, modeargs ...string) { modeargs = modeargs[1:] } else if !modeop { ch.Modes.Limit = 0 - } else { - logging.Warn("Channel.ParseModes(): not enough arguments to "+ - "process MODE %s %s%c", ch.Name, modestr, m) } case 'q', 'a', 'o', 'h', 'v': if len(modeargs) != 0 { @@ -204,16 +190,8 @@ func (ch *Channel) ParseModes(modes string, modeargs ...string) { cp.Voice = modeop } modeargs = modeargs[1:] - } else { - logging.Warn("Channel.ParseModes(): untracked nick %s "+ - "received MODE on channel %s", modeargs[0], ch.Name) } - } else { - logging.Warn("Channel.ParseModes(): not enough arguments to "+ - "process MODE %s %s%c", ch.Name, modestr, m) } - default: - logging.Info("Channel.ParseModes(): unknown mode char %c", m) } } } diff --git a/state/nick.go b/state/nick.go index 96a0b48..a9377eb 100644 --- a/state/nick.go +++ b/state/nick.go @@ -1,7 +1,6 @@ package state import ( - "github.com/fluffle/golog/logging" "reflect" ) @@ -69,8 +68,6 @@ func (nk *Nick) addChannel(ch *Channel, cp *ChanPrivs) { if _, ok := nk.chans[ch]; !ok { nk.chans[ch] = cp nk.lookup[ch.Name] = ch - } else { - logging.Warn("Nick.addChannel(): %s already on %s.", nk.Nick, ch.Name) } } @@ -79,8 +76,6 @@ func (nk *Nick) delChannel(ch *Channel) { if _, ok := nk.chans[ch]; ok { delete(nk.chans, ch) delete(nk.lookup, ch.Name) - } else { - logging.Warn("Nick.delChannel(): %s not on %s.", nk.Nick, ch.Name) } } @@ -105,8 +100,6 @@ func (nk *Nick) ParseModes(modes string) { nk.Modes.HiddenHost = modeop case 'z': nk.Modes.SSL = modeop - default: - logging.Info("Nick.ParseModes(): unknown mode char %c", m) } } } diff --git a/state/tracker.go b/state/tracker.go index 893b68d..bae7c61 100644 --- a/state/tracker.go +++ b/state/tracker.go @@ -1,9 +1,5 @@ package state -import ( - "github.com/fluffle/golog/logging" -) - // The state manager interface type Tracker interface { // Nick methods @@ -63,7 +59,6 @@ func (st *stateTracker) Wipe() { // can be properly tracked for state management purposes. func (st *stateTracker) NewNick(n string) *Nick { if _, ok := st.nicks[n]; ok { - logging.Warn("Tracker.NewNick(): %s already tracked.", n) return nil } st.nicks[n] = NewNick(n) @@ -92,11 +87,7 @@ func (st *stateTracker) ReNick(old, neu string) { delete(ch.lookup, old) ch.lookup[neu] = nk } - } else { - logging.Warn("Tracker.ReNick(): %s already exists.", neu) } - } else { - logging.Warn("Tracker.ReNick(): %s not tracked.", old) } } @@ -105,30 +96,19 @@ func (st *stateTracker) DelNick(n string) { if nk, ok := st.nicks[n]; ok { if nk != st.me { st.delNick(nk) - } else { - logging.Warn("Tracker.DelNick(): won't delete myself.") } - } else { - logging.Warn("Tracker.DelNick(): %s not tracked.", n) } } func (st *stateTracker) delNick(nk *Nick) { if nk == st.me { // Shouldn't get here => internal state tracking code is fubar. - logging.Error("Tracker.DelNick(): TRYING TO DELETE ME :-(") return } delete(st.nicks, nk.Nick) for ch, _ := range nk.chans { nk.delChannel(ch) ch.delNick(nk) - if len(ch.nicks) == 0 { - // Deleting a nick from tracking shouldn't empty any channels as - // *we* should be on the channel with them to be tracking them. - logging.Error("Tracker.delNick(): deleting nick %s emptied "+ - "channel %s, this shouldn't happen!", nk.Nick, ch.Name) - } } } @@ -136,7 +116,6 @@ func (st *stateTracker) delNick(nk *Nick) { // can be properly tracked for state management purposes. func (st *stateTracker) NewChannel(c string) *Channel { if _, ok := st.chans[c]; ok { - logging.Warn("Tracker.NewChannel(): %s already tracked.", c) return nil } st.chans[c] = NewChannel(c) @@ -155,8 +134,6 @@ func (st *stateTracker) GetChannel(c string) *Channel { func (st *stateTracker) DelChannel(c string) { if ch, ok := st.chans[c]; ok { st.delChannel(ch) - } else { - logging.Warn("Tracker.DelChannel(): %s not tracked.", c) } } @@ -191,22 +168,15 @@ func (st *stateTracker) IsOn(c, n string) (*ChanPrivs, bool) { // Associates an already known nick with an already known channel. func (st *stateTracker) Associate(ch *Channel, nk *Nick) *ChanPrivs { if ch == nil || nk == nil { - logging.Error("Tracker.Associate(): passed nil values :-(") return nil } else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch { // As we can implicitly delete both nicks and channels from being // tracked by dissociating one from the other, we should verify that // we're not being passed an old Nick or Channel. - logging.Error("Tracker.Associate(): channel %s not found in "+ - "(or differs from) internal state.", ch.Name) return nil } else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk { - logging.Error("Tracker.Associate(): nick %s not found in "+ - "(or differs from) internal state.", nk.Nick) return nil } else if _, ok := nk.IsOn(ch); ok { - logging.Warn("Tracker.Associate(): %s already on %s.", - nk.Nick, ch.Name) return nil } cp := new(ChanPrivs) @@ -220,19 +190,12 @@ func (st *stateTracker) Associate(ch *Channel, nk *Nick) *ChanPrivs { // any common channels with, and channels we're no longer on. func (st *stateTracker) Dissociate(ch *Channel, nk *Nick) { if ch == nil || nk == nil { - logging.Error("Tracker.Dissociate(): passed nil values :-(") } else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch { // As we can implicitly delete both nicks and channels from being // tracked by dissociating one from the other, we should verify that // we're not being passed an old Nick or Channel. - logging.Error("Tracker.Dissociate(): channel %s not found in "+ - "(or differs from) internal state.", ch.Name) } else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk { - logging.Error("Tracker.Dissociate(): nick %s not found in "+ - "(or differs from) internal state.", nk.Nick) } else if _, ok := nk.IsOn(ch); !ok { - logging.Warn("Tracker.Dissociate(): %s not on %s.", - nk.Nick, ch.Name) } else if nk == st.me { // I'm leaving the channel for some reason, so it won't be tracked. st.delChannel(ch) diff --git a/state/tracker_test.go b/state/tracker_test.go index e6f3584..a14645e 100644 --- a/state/tracker_test.go +++ b/state/tracker_test.go @@ -1,16 +1,9 @@ package state import ( - "github.com/fluffle/golog/logging" "testing" ) -func init() { - // This is probably a dirty hack... - logging.InitFromFlags() - logging.SetLogLevel(logging.LogFatal) -} - func TestSTNewTracker(t *testing.T) { st := NewTracker("mynick")