Merge pull request #75 from parsley42/master
Let slack use an external logger
Norberto Lopes
7 years ago
6 | 6 |
"fmt"
|
7 | 7 |
"io"
|
8 | 8 |
"io/ioutil"
|
9 | |
"log"
|
10 | 9 |
"mime/multipart"
|
11 | 10 |
"net/http"
|
12 | 11 |
"net/url"
|
|
76 | 75 |
|
77 | 76 |
// FIXME: will be api.Debugf
|
78 | 77 |
if debug {
|
79 | |
log.Printf("parseResponseBody: %s\n", string(response))
|
|
78 |
logger.Printf("parseResponseBody: %s\n", string(response))
|
80 | 79 |
}
|
81 | 80 |
|
82 | 81 |
err = json.Unmarshal(response, &intf)
|
5 | 5 |
"net/url"
|
6 | 6 |
)
|
7 | 7 |
|
|
8 |
var logger *log.Logger // A logger that can be set by consumers
|
8 | 9 |
/*
|
9 | 10 |
Added as a var so that we can change this for testing purposes
|
10 | 11 |
*/
|
|
37 | 38 |
debug bool
|
38 | 39 |
}
|
39 | 40 |
|
|
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 |
|
40 | 47 |
func New(token string) *Client {
|
41 | 48 |
s := &Client{}
|
42 | 49 |
s.config.token = token
|
|
65 | 72 |
|
66 | 73 |
func (api *Client) Debugf(format string, v ...interface{}) {
|
67 | 74 |
if api.debug {
|
68 | |
log.Printf(format, v...)
|
|
75 |
logger.Printf(format, v...)
|
69 | 76 |
}
|
70 | 77 |
}
|
71 | 78 |
|
72 | 79 |
func (api *Client) Debugln(v ...interface{}) {
|
73 | 80 |
if api.debug {
|
74 | |
log.Println(v...)
|
|
81 |
logger.Println(v...)
|
75 | 82 |
}
|
76 | 83 |
}
|
2 | 2 |
import (
|
3 | 3 |
"encoding/json"
|
4 | 4 |
"errors"
|
5 | |
"log"
|
6 | 5 |
"time"
|
7 | 6 |
|
8 | 7 |
"golang.org/x/net/websocket"
|
|
68 | 67 |
|
69 | 68 |
// Reconnect only makes sense if you've successfully disconnectd with Disconnect().
|
70 | 69 |
func (rtm *RTM) Reconnect() error {
|
71 | |
log.Println("RTM::Reconnect not implemented!")
|
|
70 |
logger.Println("RTM::Reconnect not implemented!")
|
72 | 71 |
return nil
|
73 | 72 |
}
|
74 | 73 |
|