aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgb.go
diff options
context:
space:
mode:
Diffstat (limited to 'nexgb/xgb.go')
-rw-r--r--nexgb/xgb.go32
1 files changed, 15 insertions, 17 deletions
diff --git a/nexgb/xgb.go b/nexgb/xgb.go
index e5f4b1f..b2bf84b 100644
--- a/nexgb/xgb.go
+++ b/nexgb/xgb.go
@@ -5,13 +5,11 @@ import (
"io"
"log"
"net"
+ "os"
"sync"
)
-func init() {
- log.SetFlags(0)
- log.SetPrefix("XGB:")
-}
+var logger = log.New(os.Stderr, "XGB: ", 0)
const (
// cookieBuffer represents the queue size of cookies existing at any
@@ -283,8 +281,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 {
- log.Printf("Write error: %s", err)
- log.Fatal("A write error is unrecoverable. Exiting...")
+ logger.Printf("Write error: %s", err)
+ logger.Fatal("A write error is unrecoverable. Exiting...")
}
}
@@ -310,8 +308,8 @@ func (c *Conn) readResponses() {
err, event, seq = nil, nil, 0
if _, err := io.ReadFull(c.conn, buf); err != nil {
- log.Printf("Read error: %s", err)
- log.Fatal("A read error is unrecoverable. Exiting...")
+ logger.Printf("Read error: %s", err)
+ logger.Fatal("A read error is unrecoverable. Exiting...")
}
switch buf[0] {
@@ -320,7 +318,7 @@ func (c *Conn) readResponses() {
// generated) by looking it up by the error number.
newErrFun, ok := newErrorFuncs[int(buf[1])]
if !ok {
- log.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
}
@@ -339,8 +337,8 @@ func (c *Conn) readResponses() {
biggerBuf := make([]byte, byteCount)
copy(biggerBuf[:32], buf)
if _, err := io.ReadFull(c.conn, biggerBuf[32:]); err != nil {
- log.Printf("Read error: %s", err)
- log.Fatal("A read error is unrecoverable. Exiting...")
+ logger.Printf("Read error: %s", err)
+ logger.Fatal("A read error is unrecoverable. Exiting...")
}
replyBytes = biggerBuf
} else {
@@ -357,7 +355,7 @@ func (c *Conn) readResponses() {
evNum := int(buf[0] & 127)
newEventFun, ok := newEventFuncs[evNum]
if !ok {
- log.Printf("BUG: Could not find event construct function "+
+ logger.Printf("BUG: Could not find event construct function "+
"for event with number %d.", evNum)
continue
}
@@ -404,8 +402,8 @@ func (c *Conn) readResponses() {
}
} else { // this is a reply
if cookie.replyChan == nil {
- log.Printf("Reply with sequence id %d does not have a "+
- "cookie with a valid reply channel.", seq)
+ logger.Printf("Reply with sequence id %d does not "+
+ "have a cookie with a valid reply channel.", seq)
continue
} else {
cookie.replyChan <- replyBytes
@@ -417,12 +415,12 @@ func (c *Conn) readResponses() {
switch {
// Checked requests with replies
case cookie.replyChan != nil && cookie.errorChan != nil:
- log.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:
- log.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)
@@ -445,7 +443,7 @@ func processEventOrError(everr eventOrError) (Event, Error) {
case Error:
return nil, ee
default:
- log.Printf("Invalid event/error type: %T", everr)
+ logger.Printf("Invalid event/error type: %T", everr)
return nil, nil
}
panic("unreachable")