From 35bfb1405804c864c4ace84b1a7e38bf7e20a639 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Thu, 23 Aug 2018 18:15:39 -0400 Subject: [PATCH] lint: don't use global `log` users can change the logger now via gavalink.Log --- lavalink.go | 11 ++++++++++- node.go | 13 ++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lavalink.go b/lavalink.go index 8c5f8ad..576b06c 100644 --- a/lavalink.go +++ b/lavalink.go @@ -2,8 +2,17 @@ package gavalink import ( "errors" + "log" + "os" ) +// Log sets the log.Logger gavalink will write to +var Log *log.Logger + +func init() { + Log = log.New(os.Stdout, "(gavalink)", 0) +} + // Lavalink manages a connection to Lavalink Nodes type Lavalink struct { shards string @@ -52,7 +61,7 @@ func (lavalink *Lavalink) AddNodes(nodeConfigs ...NodeConfig) error { } // RemoveNode removes a node from the manager -func (lavalink *Lavalink) RemoveNode(node *Node) error { +func (lavalink *Lavalink) removeNode(node *Node) error { idx := -1 for i, n := range lavalink.nodes { if n == *node { diff --git a/node.go b/node.go index f360d6d..1b5c8b1 100644 --- a/node.go +++ b/node.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "log" "net/http" "strconv" @@ -56,7 +55,7 @@ func (node *Node) open() error { node.wsConn = ws go node.listen() - log.Println("node", node.config.WebSocket, "opened") + Log.Println("node", node.config.WebSocket, "opened") return nil } @@ -73,20 +72,20 @@ func (node *Node) listen() { for { msgType, msg, err := node.wsConn.ReadMessage() if err != nil { - log.Println(err) + Log.Println(err) // try to reconnect oerr := node.open() if oerr != nil { - log.Println("node", node.config.WebSocket, "failed and could not reconnect, destroying.", err, oerr) - node.manager.RemoveNode(node) + Log.Println("node", node.config.WebSocket, "failed and could not reconnect, destroying.", err, oerr) + node.manager.removeNode(node) return } - log.Println("node", node.config.WebSocket, "reconnected") + Log.Println("node", node.config.WebSocket, "reconnected") return } err = node.onEvent(msgType, msg) // TODO: better error handling - log.Println(err) + Log.Println(err) } }