Skip to content

Commit

Permalink
replace standard logger with the global Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
vrischmann committed Nov 22, 2016
1 parent 9ec6cba commit e8ddc4f
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 32 deletions.
3 changes: 1 addition & 2 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package gocql

import (
"errors"
"log"
"net"
"time"
)
Expand Down Expand Up @@ -162,7 +161,7 @@ func (cfg *ClusterConfig) translateAddressPort(addr net.IP, port int) (net.IP, i
}
newAddr, newPort := cfg.AddressTranslator.Translate(addr, port)
if gocqlDebug {
log.Printf("gocql: translating address '%v:%d' to '%v:%d'", addr, port, newAddr, newPort)
Logger.Printf("gocql: translating address '%v:%d' to '%v:%d'", addr, port, newAddr, newPort)
}
return newAddr, newPort
}
Expand Down
7 changes: 3 additions & 4 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"net"
"strconv"
"strings"
Expand Down Expand Up @@ -501,7 +500,7 @@ func (c *Conn) recv() error {
call, ok := c.calls[head.stream]
c.mu.RUnlock()
if call == nil || call.framer == nil || !ok {
log.Printf("gocql: received response for stream which has no handler: header=%v\n", head)
Logger.Printf("gocql: received response for stream which has no handler: header=%v\n", head)
return c.discardFrame(head)
}

Expand Down Expand Up @@ -881,7 +880,7 @@ func (c *Conn) executeQuery(qry *Query) *Iter {
iter := &Iter{framer: framer}
if err := c.awaitSchemaAgreement(); err != nil {
// TODO: should have this behind a flag
log.Println(err)
Logger.Println(err)
}
// dont return an error from this, might be a good idea to give a warning
// though. The impact of this returning an error would be that the cluster
Expand Down Expand Up @@ -1092,7 +1091,7 @@ func (c *Conn) awaitSchemaAgreement() (err error) {
var schemaVersion string
for iter.Scan(&schemaVersion) {
if schemaVersion == "" {
log.Println("skipping peer entry with empty schema_version")
Logger.Println("skipping peer entry with empty schema_version")
continue
}

Expand Down
5 changes: 2 additions & 3 deletions connectionpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"math/rand"
"net"
"sync"
Expand Down Expand Up @@ -422,11 +421,11 @@ func (pool *hostConnPool) logConnectErr(err error) {
// connection refused
// these are typical during a node outage so avoid log spam.
if gocqlDebug {
log.Printf("unable to dial %q: %v\n", pool.host.Peer(), err)
Logger.Printf("unable to dial %q: %v\n", pool.host.Peer(), err)
}
} else if err != nil {
// unexpected error
log.Printf("error: failed to connect to %s due to error: %v", pool.addr, err)
Logger.Printf("error: failed to connect to %s due to error: %v", pool.addr, err)
}
}

Expand Down
7 changes: 3 additions & 4 deletions control.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
crand "crypto/rand"
"errors"
"fmt"
"log"
"math/rand"
"net"
"regexp"
Expand Down Expand Up @@ -159,7 +158,7 @@ func (c *controlConn) shuffleDial(endpoints []*HostInfo) (*Conn, error) {
return conn, nil
}

log.Printf("gocql: unable to dial control conn %v: %v\n", host.Peer(), err)
Logger.Printf("gocql: unable to dial control conn %v: %v\n", host.Peer(), err)
}

return nil, err
Expand Down Expand Up @@ -337,7 +336,7 @@ func (c *controlConn) reconnect(refreshring bool) {

if err := c.setupConn(newConn); err != nil {
newConn.Close()
log.Printf("gocql: control unable to register events: %v\n", err)
Logger.Printf("gocql: control unable to register events: %v\n", err)
return
}

Expand Down Expand Up @@ -406,7 +405,7 @@ func (c *controlConn) query(statement string, values ...interface{}) (iter *Iter
})

if gocqlDebug && iter.err != nil {
log.Printf("control: error executing %q: %v\n", statement, iter.err)
Logger.Printf("control: error executing %q: %v\n", statement, iter.err)
}

q.attempts++
Expand Down
17 changes: 8 additions & 9 deletions events.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gocql

import (
"log"
"net"
"sync"
"time"
Expand Down Expand Up @@ -74,7 +73,7 @@ func (e *eventDebouncer) debounce(frame frame) {
if len(e.events) < eventBufferSize {
e.events = append(e.events, frame)
} else {
log.Printf("%s: buffer full, dropping event frame: %s", e.name, frame)
Logger.Printf("%s: buffer full, dropping event frame: %s", e.name, frame)
}

e.mu.Unlock()
Expand All @@ -87,12 +86,12 @@ func (s *Session) handleEvent(framer *framer) {
frame, err := framer.parseFrame()
if err != nil {
// TODO: logger
log.Printf("gocql: unable to parse event frame: %v\n", err)
Logger.Printf("gocql: unable to parse event frame: %v\n", err)
return
}

if gocqlDebug {
log.Printf("gocql: handling frame: %v\n", frame)
Logger.Printf("gocql: handling frame: %v\n", frame)
}

// TODO: handle medatadata events
Expand All @@ -102,7 +101,7 @@ func (s *Session) handleEvent(framer *framer) {
case *topologyChangeEventFrame, *statusChangeEventFrame:
s.nodeEvents.debounce(frame)
default:
log.Printf("gocql: invalid event frame (%T): %v\n", f, f)
Logger.Printf("gocql: invalid event frame (%T): %v\n", f, f)
}
}

Expand Down Expand Up @@ -152,7 +151,7 @@ func (s *Session) handleNodeEvent(frames []frame) {

for _, f := range events {
if gocqlDebug {
log.Printf("gocql: dispatching event: %+v\n", f)
Logger.Printf("gocql: dispatching event: %+v\n", f)
}

switch f.change {
Expand All @@ -177,7 +176,7 @@ func (s *Session) handleNewNode(ip net.IP, port int, waitForBinary bool) {
var err error
hostInfo, err = s.control.fetchHostInfo(ip, port)
if err != nil {
log.Printf("gocql: events: unable to fetch host info for (%s:%d): %v\n", ip, port, err)
Logger.Printf("gocql: events: unable to fetch host info for (%s:%d): %v\n", ip, port, err)
return
}
} else {
Expand Down Expand Up @@ -233,7 +232,7 @@ func (s *Session) handleRemovedNode(ip net.IP, port int) {

func (s *Session) handleNodeUp(ip net.IP, port int, waitForBinary bool) {
if gocqlDebug {
log.Printf("gocql: Session.handleNodeUp: %s:%d\n", ip.String(), port)
Logger.Printf("gocql: Session.handleNodeUp: %s:%d\n", ip.String(), port)
}

host := s.ring.getHost(ip)
Expand Down Expand Up @@ -262,7 +261,7 @@ func (s *Session) handleNodeUp(ip net.IP, port int, waitForBinary bool) {

func (s *Session) handleNodeDown(ip net.IP, port int) {
if gocqlDebug {
log.Printf("gocql: Session.handleNodeDown: %s:%d\n", ip.String(), port)
Logger.Printf("gocql: Session.handleNodeDown: %s:%d\n", ip.String(), port)
}

host := s.ring.getHost(ip)
Expand Down
3 changes: 1 addition & 2 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"net"
"runtime"
"strings"
Expand Down Expand Up @@ -472,7 +471,7 @@ func (f *framer) parseFrame() (frame frame, err error) {
warnings := f.readStringList()
// what to do with warnings?
for _, v := range warnings {
log.Println(v)
Logger.Println(v)
}
}

Expand Down
3 changes: 1 addition & 2 deletions host_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gocql

import (
"fmt"
"log"
"net"
"strconv"
"strings"
Expand Down Expand Up @@ -343,7 +342,7 @@ func (r *ringDescriber) GetHosts() (hosts []*HostInfo, partitioner string, err e
host := &HostInfo{port: r.session.cfg.Port}
err := rows.Scan(&host.peer, &host.dataCenter, &host.rack, &host.hostId, &host.tokens, &host.version)
if err != nil {
log.Println(err)
Logger.Println(err)
continue
}

Expand Down
3 changes: 1 addition & 2 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"log"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -855,7 +854,7 @@ func (t *typeParser) parse() typeParserResult {
var name string
decoded, err := hex.DecodeString(*param.name)
if err != nil {
log.Printf(
Logger.Printf(
"Error parsing type '%s', contains collection name '%s' with an invalid format: %v",
t.input,
*param.name,
Expand Down
3 changes: 1 addition & 2 deletions policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package gocql

import (
"fmt"
"log"
"net"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -307,7 +306,7 @@ func (t *tokenAwareHostPolicy) resetTokenRing() {
hosts := t.hosts.get()
tokenRing, err := newTokenRing(t.partitioner, hosts)
if err != nil {
log.Printf("Unable to update the token ring due to error: %s", err)
Logger.Printf("Unable to update the token ring due to error: %s", err)
return
}

Expand Down
3 changes: 1 addition & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io"
"log"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -231,7 +230,7 @@ func (s *Session) reconnectDownedHosts(intv time.Duration) {
for _, h := range hosts {
buf.WriteString("[" + h.Peer().String() + ":" + h.State().String() + "]")
}
log.Println(buf.String())
Logger.Println(buf.String())
}

for _, h := range hosts {
Expand Down

0 comments on commit e8ddc4f

Please sign in to comment.