1
0
Fork 0
mirror of https://github.com/fluffle/goirc synced 2025-05-12 18:44:50 +00:00

Minimally invasive change to put logging behind a user-replaceable interface.

This could probably be done better, and there are probably awful caveats
and hidden gotchas with this approach. I REGRET NOTHING.
This commit is contained in:
Alex Bramley 2013-09-27 22:19:40 +01:00
parent 06a9cb5d0f
commit 5bb0c8278d
10 changed files with 60 additions and 15 deletions

View file

@ -4,8 +4,8 @@ import (
"bufio"
"crypto/tls"
"fmt"
"github.com/fluffle/goirc/logging"
"github.com/fluffle/goirc/state"
"github.com/fluffle/golog/logging"
"io"
"net"
"strings"
@ -107,9 +107,13 @@ 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.")
if cfg == nil {
cfg = NewConfig("__idiot__")
}
if cfg.Me == nil || cfg.Me.Nick == "" || cfg.Me.Ident == "" {
cfg.Me = state.NewNick("__idiot__")
cfg.Me.Ident = "goirc"
cfg.Me.Name = "Powered by GoIRC"
}
conn := &Conn{
cfg: cfg,
@ -309,7 +313,7 @@ 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.",
logging.Info("irc.rateLimit(): Flood! Sleeping for %.2f secs.",
t.Seconds())
<-time.After(t)
}

View file

@ -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

View file

@ -1,7 +1,7 @@
package client
import (
"github.com/fluffle/golog/logging"
"github.com/fluffle/goirc/logging"
"runtime"
"strings"
"sync"

View file

@ -136,11 +136,11 @@ func (m *mockNetConn) Close() error {
}
func (m *mockNetConn) LocalAddr() net.Addr {
return &net.IPAddr{net.IPv4(127, 0, 0, 1)}
return &net.IPAddr{net.IPv4(127, 0, 0, 1), ""}
}
func (m *mockNetConn) RemoteAddr() net.Addr {
return &net.IPAddr{net.IPv4(127, 0, 0, 1)}
return &net.IPAddr{net.IPv4(127, 0, 0, 1), ""}
}
func (m *mockNetConn) SetDeadline(t time.Time) error {

View file

@ -4,7 +4,7 @@ package client
// to manage tracking state for an IRC connection
import (
"github.com/fluffle/golog/logging"
"github.com/fluffle/goirc/logging"
"strings"
)