Skip to content

Commit

Permalink
Deprecate extra Intercept methods on InterceptLogger
Browse files Browse the repository at this point in the history
These interface methods are equivalent to the methods that already exist
on the embedded Logger interface. The interceptLogger can implement the
Logger insterface instead of adding extra interface methods.
  • Loading branch information
dnephin committed Oct 19, 2020
1 parent 0722fda commit ec464e9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions interceptlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,23 @@ func (i *interceptLogger) DeregisterSink(sink SinkAdapter) {
atomic.AddInt32(i.sinkCount, -1)
}

// Create a *log.Logger that will send it's data through this Logger. This
// allows packages that expect to be using the standard library to log to
// actually use this logger, which will also send to any registered sinks.
func (i *interceptLogger) StandardLoggerIntercept(opts *StandardLoggerOptions) *log.Logger {
return i.StandardLogger(opts)
}

func (i *interceptLogger) StandardLogger(opts *StandardLoggerOptions) *log.Logger {
if opts == nil {
opts = &StandardLoggerOptions{}
}

return log.New(i.StandardWriterIntercept(opts), "", 0)
return log.New(i.StandardWriter(opts), "", 0)
}

func (i *interceptLogger) StandardWriterIntercept(opts *StandardLoggerOptions) io.Writer {
return i.StandardWriter(opts)
}

func (i *interceptLogger) StandardWriter(opts *StandardLoggerOptions) io.Writer {
return &stdlogAdapter{
log: i,
inferLevels: opts.InferLevels,
Expand Down
2 changes: 1 addition & 1 deletion interceptlogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func TestInterceptLogger(t *testing.T) {
Output: &buf,
})

standard := intercept.StandardLoggerIntercept(&StandardLoggerOptions{InferLevels: true})
standard := intercept.StandardLogger(&StandardLoggerOptions{InferLevels: true})

sink := NewSinkAdapter(&LoggerOptions{
Level: Debug,
Expand Down
4 changes: 2 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ type InterceptLogger interface {
// the current name as well.
ResetNamedIntercept(name string) InterceptLogger

// Return a value that conforms to the stdlib log.Logger interface
// Deprecated: use StandardLogger
StandardLoggerIntercept(opts *StandardLoggerOptions) *log.Logger

// Return a value that conforms to io.Writer, which can be passed into log.SetOutput()
// Deprecated: use StandardWriter
StandardWriterIntercept(opts *StandardLoggerOptions) io.Writer
}

Expand Down

0 comments on commit ec464e9

Please sign in to comment.