Skip to content

Commit

Permalink
logging updates
Browse files Browse the repository at this point in the history
  • Loading branch information
James Lawrence authored and james-lawrence committed Oct 6, 2018
1 parent 01a2128 commit 5a08dea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import (
"fmt"
)

// logProvider is a logger interface compatible with both stdlib and some
// 3rd party loggers such as logrus.
type logProvider interface {
// logger is a logger interface compatible with both stdlib and some
// 3rd party loggers.
type logger interface {
Output(int, string) error
}

// logInternal represents the internal logging api we use.
type logInternal interface {
// ilogger represents the internal logging api we use.
type ilogger interface {
logger
Print(...interface{})
Printf(string, ...interface{})
Println(...interface{})
Output(int, string) error
}

type debug interface {
Expand All @@ -27,23 +27,23 @@ type debug interface {
Debugln(v ...interface{})
}

// ilogger implements the additional methods used by our internal logging.
type ilogger struct {
logProvider
// internalLog implements the additional methods used by our internal logging.
type internalLog struct {
logger
}

// Println replicates the behaviour of the standard logger.
func (t ilogger) Println(v ...interface{}) {
func (t internalLog) Println(v ...interface{}) {
t.Output(2, fmt.Sprintln(v...))
}

// Printf replicates the behaviour of the standard logger.
func (t ilogger) Printf(format string, v ...interface{}) {
func (t internalLog) Printf(format string, v ...interface{}) {
t.Output(2, fmt.Sprintf(format, v...))
}

// Print replicates the behaviour of the standard logger.
func (t ilogger) Print(v ...interface{}) {
func (t internalLog) Print(v ...interface{}) {
t.Output(2, fmt.Sprint(v...))
}

Expand Down
2 changes: 1 addition & 1 deletion logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestLogging(t *testing.T) {
buf := bytes.NewBufferString("")
logger := ilogger{logProvider: log.New(buf, "", 0|log.Lshortfile)}
logger := internalLog{logger: log.New(buf, "", 0|log.Lshortfile)}
logger.Println("test line 123")
assert.Equal(t, buf.String(), "logger_test.go:14: test line 123\n")
buf.Truncate(0)
Expand Down
6 changes: 3 additions & 3 deletions slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Client struct {
token string
info Info
debug bool
log logInternal
log ilogger
httpclient httpClient
}

Expand All @@ -74,9 +74,9 @@ func OptionDebug(b bool) func(*Client) {
}

// OptionLog set logging for client.
func OptionLog(l logProvider) func(*Client) {
func OptionLog(l logger) func(*Client) {
return func(c *Client) {
c.log = ilogger{logProvider: l}
c.log = internalLog{logger: l}
}
}

Expand Down

0 comments on commit 5a08dea

Please sign in to comment.