Skip to content

Commit 486c233

Browse files
authoredMay 31, 2024··
Minor logger improovments (#1495)
Move WithLogger interface to other logger interfaces
1 parent 4dd1ed8 commit 486c233

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
 

‎log/logger.go

+6
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@ type (
3939
WithSkipCallers interface {
4040
WithCallerSkip(int) Logger
4141
}
42+
43+
// WithLogger is an optional interface that prepend every log entry with keyvals.
44+
// This call must not mutate the original logger.
45+
WithLogger interface {
46+
With(keyvals ...interface{}) Logger
47+
}
4248
)

‎log/with_logger.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424

2525
package log
2626

27-
// WithLogger is an interface that prepend every log entry with keyvals.
28-
type WithLogger interface {
29-
With(keyvals ...interface{}) Logger
30-
}
31-
3227
// With creates a child Logger that includes the supplied key-value pairs in each log entry. It does this by
3328
// using the supplied logger if it implements WithLogger; otherwise, it does so by intercepting every log call.
3429
func With(logger Logger, keyvals ...interface{}) Logger {
@@ -57,7 +52,7 @@ type withLogger struct {
5752
}
5853

5954
func newWithLogger(logger Logger, keyvals ...interface{}) *withLogger {
60-
return &withLogger{logger: logger, keyvals: keyvals}
55+
return &withLogger{logger: Skip(logger, 1), keyvals: keyvals}
6156
}
6257

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

0 commit comments

Comments
 (0)
Please sign in to comment.