| 1 | package socketmode |
| 2 | |
| 3 | import "fmt" |
| 4 | |
| 5 | // TODO merge logger, ilogger, and internalLogger with the top-level package's equivalents |
| 6 | |
| 7 | // logger is a logger interface compatible with both stdlib and some |
| 8 | // 3rd party loggers. |
| 9 | type logger interface { |
| 10 | Output(int, string) error |
| 11 | } |
| 12 | |
| 13 | // ilogger represents the internal logging api we use. |
| 14 | type ilogger interface { |
| 15 | logger |
| 16 | Print(...interface{}) |
| 17 | Printf(string, ...interface{}) |
| 18 | Println(...interface{}) |
| 19 | } |
| 20 | |
| 21 | // internalLog implements the additional methods used by our internal logging. |
| 22 | type internalLog struct { |
| 23 | logger |
| 24 | } |
| 25 | |
| 26 | // Println replicates the behaviour of the standard logger. |
| 27 | func (t internalLog) Println(v ...interface{}) { |
| 28 | t.Output(2, fmt.Sprintln(v...)) |
| 29 | } |
| 30 | |
| 31 | // Printf replicates the behaviour of the standard logger. |
| 32 | func (t internalLog) Printf(format string, v ...interface{}) { |
| 33 | t.Output(2, fmt.Sprintf(format, v...)) |
| 34 | } |
| 35 | |
| 36 | // Print replicates the behaviour of the standard logger. |
| 37 | func (t internalLog) Print(v ...interface{}) { |
| 38 | t.Output(2, fmt.Sprint(v...)) |
| 39 | } |
| 40 | |
| 41 | func (smc *Client) Debugf(format string, v ...interface{}) { |
| 42 | if smc.debug { |
| 43 | smc.log.Output(2, fmt.Sprintf(format, v...)) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | func (smc *Client) Debugln(v ...interface{}) { |
| 48 | if smc.debug { |
| 49 | smc.log.Output(2, fmt.Sprintln(v...)) |
| 50 | } |
| 51 | } |