Skip to content

Commit

Permalink
Minor logger improovments (temporalio#1495)
Browse files Browse the repository at this point in the history
Move WithLogger interface to other logger interfaces
  • Loading branch information
jetexe authored May 31, 2024
1 parent 4dd1ed8 commit 486c233
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 6 additions & 0 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ type (
WithSkipCallers interface {
WithCallerSkip(int) Logger
}

// WithLogger is an optional interface that prepend every log entry with keyvals.
// This call must not mutate the original logger.
WithLogger interface {
With(keyvals ...interface{}) Logger
}
)
7 changes: 1 addition & 6 deletions log/with_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@

package log

// WithLogger is an interface that prepend every log entry with keyvals.
type WithLogger interface {
With(keyvals ...interface{}) Logger
}

// With creates a child Logger that includes the supplied key-value pairs in each log entry. It does this by
// using the supplied logger if it implements WithLogger; otherwise, it does so by intercepting every log call.
func With(logger Logger, keyvals ...interface{}) Logger {
Expand Down Expand Up @@ -57,7 +52,7 @@ type withLogger struct {
}

func newWithLogger(logger Logger, keyvals ...interface{}) *withLogger {
return &withLogger{logger: logger, keyvals: keyvals}
return &withLogger{logger: Skip(logger, 1), keyvals: keyvals}
}

func (l *withLogger) prependKeyvals(keyvals []interface{}) []interface{} {
Expand Down

0 comments on commit 486c233

Please sign in to comment.