Codebase list golang-github-nlopes-slack / 67c6939
Merge pull request #75 from parsley42/master Let slack use an external logger Norberto Lopes 7 years ago
3 changed file(s) with 11 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
66 "fmt"
77 "io"
88 "io/ioutil"
9 "log"
109 "mime/multipart"
1110 "net/http"
1211 "net/url"
7675
7776 // FIXME: will be api.Debugf
7877 if debug {
79 log.Printf("parseResponseBody: %s\n", string(response))
78 logger.Printf("parseResponseBody: %s\n", string(response))
8079 }
8180
8281 err = json.Unmarshal(response, &intf)
55 "net/url"
66 )
77
8 var logger *log.Logger // A logger that can be set by consumers
89 /*
910 Added as a var so that we can change this for testing purposes
1011 */
3738 debug bool
3839 }
3940
41 // SetLogger let's library users supply a logger, so that api debugging
42 // can be logged along with the application's debugging info.
43 func SetLogger(l *log.Logger) {
44 logger = l
45 }
46
4047 func New(token string) *Client {
4148 s := &Client{}
4249 s.config.token = token
6572
6673 func (api *Client) Debugf(format string, v ...interface{}) {
6774 if api.debug {
68 log.Printf(format, v...)
75 logger.Printf(format, v...)
6976 }
7077 }
7178
7279 func (api *Client) Debugln(v ...interface{}) {
7380 if api.debug {
74 log.Println(v...)
81 logger.Println(v...)
7582 }
7683 }
22 import (
33 "encoding/json"
44 "errors"
5 "log"
65 "time"
76
87 "golang.org/x/net/websocket"
6867
6968 // Reconnect only makes sense if you've successfully disconnectd with Disconnect().
7069 func (rtm *RTM) Reconnect() error {
71 log.Println("RTM::Reconnect not implemented!")
70 logger.Println("RTM::Reconnect not implemented!")
7271 return nil
7372 }
7473