aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgb.go
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-16 23:57:26 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-16 23:57:26 -0400
commitacb84171e55d46dc1a5b9cc10b2bff53c2d2846b (patch)
treea318f368d75796fd8d70208523663dcdcdf89b28 /nexgb/xgb.go
parent424f293671b256bb5e253eea1cbb83519f4243f3 (diff)
downloadhaven-acb84171e55d46dc1a5b9cc10b2bff53c2d2846b.tar.gz
haven-acb84171e55d46dc1a5b9cc10b2bff53c2d2846b.tar.xz
haven-acb84171e55d46dc1a5b9cc10b2bff53c2d2846b.zip
Add new logger type so that it can be shut off.
Diffstat (limited to 'nexgb/xgb.go')
-rw-r--r--nexgb/xgb.go28
1 files changed, 13 insertions, 15 deletions
diff --git a/nexgb/xgb.go b/nexgb/xgb.go
index dad0ed5..b0a7307 100644
--- a/nexgb/xgb.go
+++ b/nexgb/xgb.go
@@ -3,14 +3,12 @@ package xgb
import (
"errors"
"io"
- "log"
"net"
- "os"
"sync"
)
var (
- Logger = log.New(os.Stderr, "XGB: ", 0)
+ logger = newLogger()
// ExtLock is a lock used whenever new extensions are initialized.
// It should not be used. It is exported for use in the extension
@@ -304,8 +302,8 @@ func (c *Conn) sendRequests() {
// writeBuffer is a convenience function for writing a byte slice to the wire.
func (c *Conn) writeBuffer(buf []byte) {
if _, err := c.conn.Write(buf); err != nil {
- Logger.Printf("Write error: %s", err)
- Logger.Fatal("A write error is unrecoverable. Exiting...")
+ logger.Printf("Write error: %s", err)
+ logger.Fatal("A write error is unrecoverable. Exiting...")
}
}
@@ -333,8 +331,8 @@ func (c *Conn) readResponses() {
err, event, seq = nil, nil, 0
if _, err := io.ReadFull(c.conn, buf); err != nil {
- Logger.Printf("Read error: %s", err)
- Logger.Fatal("A read error is unrecoverable. Exiting...")
+ logger.Printf("Read error: %s", err)
+ logger.Fatal("A read error is unrecoverable. Exiting...")
}
switch buf[0] {
@@ -343,7 +341,7 @@ func (c *Conn) readResponses() {
// generated) by looking it up by the error number.
newErrFun, ok := NewErrorFuncs[int(buf[1])]
if !ok {
- Logger.Printf("BUG: Could not find error constructor function "+
+ logger.Printf("BUG: Could not find error constructor function "+
"for error with number %d.", buf[1])
continue
}
@@ -362,8 +360,8 @@ func (c *Conn) readResponses() {
biggerBuf := make([]byte, byteCount)
copy(biggerBuf[:32], buf)
if _, err := io.ReadFull(c.conn, biggerBuf[32:]); err != nil {
- Logger.Printf("Read error: %s", err)
- Logger.Fatal("A read error is unrecoverable. Exiting...")
+ logger.Printf("Read error: %s", err)
+ logger.Fatal("A read error is unrecoverable. Exiting...")
}
replyBytes = biggerBuf
} else {
@@ -380,7 +378,7 @@ func (c *Conn) readResponses() {
evNum := int(buf[0] & 127)
newEventFun, ok := NewEventFuncs[evNum]
if !ok {
- Logger.Printf("BUG: Could not find event construct function "+
+ logger.Printf("BUG: Could not find event construct function "+
"for event with number %d.", evNum)
continue
}
@@ -429,7 +427,7 @@ func (c *Conn) readResponses() {
}
} else { // this is a reply
if cookie.replyChan == nil {
- Logger.Printf("Reply with sequence id %d does not "+
+ logger.Printf("Reply with sequence id %d does not "+
"have a cookie with a valid reply channel.", seq)
continue
} else {
@@ -442,12 +440,12 @@ func (c *Conn) readResponses() {
switch {
// Checked requests with replies
case cookie.replyChan != nil && cookie.errorChan != nil:
- Logger.Printf("Found cookie with sequence id %d that is "+
+ logger.Printf("Found cookie with sequence id %d that is "+
"expecting a reply but will never get it. Currently "+
"on sequence number %d", cookie.Sequence, seq)
// Unchecked requests with replies
case cookie.replyChan != nil && cookie.pingChan != nil:
- Logger.Printf("Found cookie with sequence id %d that is "+
+ logger.Printf("Found cookie with sequence id %d that is "+
"expecting a reply (and not an error) but will never "+
"get it. Currently on sequence number %d",
cookie.Sequence, seq)
@@ -470,7 +468,7 @@ func processEventOrError(everr eventOrError) (Event, Error) {
case Error:
return nil, ee
default:
- Logger.Printf("Invalid event/error type: %T", everr)
+ logger.Printf("Invalid event/error type: %T", everr)
return nil, nil
}
panic("unreachable")