Merge pull request #22 from darkliquid/public-log

Make IRC logger public. No reason for disallowing overrides.
This commit is contained in:
Thomas Jager 2014-02-10 21:39:55 +01:00
commit 33a06eb72b
3 changed files with 12 additions and 12 deletions

12
irc.go
View File

@ -57,7 +57,7 @@ func (irc *Connection) readLoop() {
msg = msg[i+1 : len(msg)] msg = msg[i+1 : len(msg)]
} else { } else {
irc.log.Printf("Misformed msg from server: %#s\n", msg) irc.Log.Printf("Misformed msg from server: %#s\n", msg)
} }
if i, j := strings.Index(event.Source, "!"), strings.Index(event.Source, "@"); i > -1 && j > -1 { if i, j := strings.Index(event.Source, "!"), strings.Index(event.Source, "@"); i > -1 && j > -1 {
@ -101,7 +101,7 @@ func (irc *Connection) writeLoop() {
} }
if irc.Debug { if irc.Debug {
irc.log.Printf("--> %s\n", b) irc.Log.Printf("--> %s\n", b)
} }
// Set a write deadline based on the time out // Set a write deadline based on the time out
@ -157,11 +157,11 @@ func (irc *Connection) Loop() {
if irc.stopped { if irc.stopped {
break break
} }
irc.log.Printf("Error: %s\n", err) irc.Log.Printf("Error: %s\n", err)
irc.Disconnect() irc.Disconnect()
for !irc.stopped { for !irc.stopped {
if err = irc.Connect(irc.server); err != nil { if err = irc.Connect(irc.server); err != nil {
irc.log.Printf("Error: %s\n", err) irc.Log.Printf("Error: %s\n", err)
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} else { } else {
break break
@ -256,7 +256,7 @@ func (irc *Connection) Connect(server string) error {
if err != nil { if err != nil {
return err return err
} }
irc.log.Printf("Connected to %s (%s)\n", irc.server, irc.socket.RemoteAddr()) irc.Log.Printf("Connected to %s (%s)\n", irc.server, irc.socket.RemoteAddr())
irc.pread = make(chan string, 10) irc.pread = make(chan string, 10)
irc.pwrite = make(chan string, 10) irc.pwrite = make(chan string, 10)
@ -278,7 +278,7 @@ func IRC(nick, user string) *Connection {
irc := &Connection{ irc := &Connection{
nick: nick, nick: nick,
user: user, user: user,
log: log.New(os.Stdout, "", log.LstdFlags), Log: log.New(os.Stdout, "", log.LstdFlags),
readerExit: make(chan bool), readerExit: make(chan bool),
writerExit: make(chan bool), writerExit: make(chan bool),
pingerExit: make(chan bool), pingerExit: make(chan bool),

View File

@ -26,10 +26,10 @@ func (irc *Connection) ReplaceCallback(eventcode string, i int, callback func(*E
event[i] = callback event[i] = callback
return return
} }
irc.log.Printf("Event found, but no callback found at index %d. Use AddCallback\n", i) irc.Log.Printf("Event found, but no callback found at index %d. Use AddCallback\n", i)
return return
} }
irc.log.Printf("Event not found. Use AddCallBack\n") irc.Log.Printf("Event not found. Use AddCallBack\n")
} }
func (irc *Connection) RunCallbacks(event *Event) { func (irc *Connection) RunCallbacks(event *Event) {
@ -64,7 +64,7 @@ func (irc *Connection) RunCallbacks(event *Event) {
if callbacks, ok := irc.events[event.Code]; ok { if callbacks, ok := irc.events[event.Code]; ok {
if irc.VerboseCallbackHandler { if irc.VerboseCallbackHandler {
irc.log.Printf("%v (%v) >> %#v\n", event.Code, len(callbacks), event) irc.Log.Printf("%v (%v) >> %#v\n", event.Code, len(callbacks), event)
} }
for _, callback := range callbacks { for _, callback := range callbacks {
@ -72,7 +72,7 @@ func (irc *Connection) RunCallbacks(event *Event) {
} }
} else if irc.VerboseCallbackHandler { } else if irc.VerboseCallbackHandler {
irc.log.Printf("%v (0) >> %#v\n", event.Code, event) irc.Log.Printf("%v (0) >> %#v\n", event.Code, event)
} }
} }
@ -121,7 +121,7 @@ func (irc *Connection) setupCallbacks() {
ns, _ := strconv.ParseInt(e.Message, 10, 64) ns, _ := strconv.ParseInt(e.Message, 10, 64)
delta := time.Duration(time.Now().UnixNano() - ns) delta := time.Duration(time.Now().UnixNano() - ns)
if irc.Debug { if irc.Debug {
irc.log.Printf("Lag: %vs\n", delta) irc.Log.Printf("Lag: %vs\n", delta)
} }
}) })

View File

@ -38,7 +38,7 @@ type Connection struct {
lastMessage time.Time lastMessage time.Time
VerboseCallbackHandler bool VerboseCallbackHandler bool
log *log.Logger Log *log.Logger
stopped bool stopped bool
} }