Skip to content

Commit

Permalink
Change name to satisfy linter
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskorn committed Oct 9, 2024
1 parent e93c3a0 commit 2c3d911
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions spanlogger/spanlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ func (s *SpanLogger) SetSpanAndLogTag(key string, value interface{}) {
s.logger.Store(&wrappedLogger)
}

// SpanLoggerAwareCaller is like log.Caller, but ensures that the caller information is
// Caller is like github.com/go-kit/log's Caller, but ensures that the caller information is
// that of the caller to SpanLogger (if SpanLogger is being used), not SpanLogger itself.
//
// defaultStackDepth should be the number of stack frames to skip by default, as would be
// passed to github.com/go-kit/log's Caller method.
func SpanLoggerAwareCaller(defaultStackDepth int) log.Valuer {
func Caller(defaultStackDepth int) log.Valuer {
return func() interface{} {
stackDepth := defaultStackDepth

Expand All @@ -221,7 +221,7 @@ func SpanLoggerAwareCaller(defaultStackDepth int) log.Valuer {
}
}

// This is based on github.com/go-kit/log's Caller, but modified for use by SpanLoggerAwareCaller above.
// This is based on github.com/go-kit/log's Caller, but modified for use by Caller above.
func formatCallerInfoForLog(file string, line int) string {
idx := strings.LastIndexByte(file, '/')
return file[idx+1:] + ":" + strconv.Itoa(line)
Expand Down
12 changes: 6 additions & 6 deletions spanlogger/spanlogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func BenchmarkSpanLoggerWithRealLogger(b *testing.B) {
b.Run(name, func(b *testing.B) {
buf := bytes.NewBuffer(nil)
logger := dskit_log.NewGoKitWithWriter("logfmt", buf)
logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", SpanLoggerAwareCaller(5))
logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", Caller(5))

if debugEnabled {
logger = level.NewFilter(logger, level.AllowAll())
Expand Down Expand Up @@ -273,8 +273,8 @@ func BenchmarkSpanLoggerAwareCaller(b *testing.B) {
runBenchmark(b, log.Caller(defaultStackDepth))
})

b.Run("with dskit's SpanLoggerAwareCaller", func(b *testing.B) {
runBenchmark(b, SpanLoggerAwareCaller(defaultStackDepth))
b.Run("with dskit's spanlogger.Caller", func(b *testing.B) {
runBenchmark(b, Caller(defaultStackDepth))
})
}

Expand All @@ -297,23 +297,23 @@ func TestSpanLoggerAwareCaller(t *testing.T) {
// This is based on Mimir's default logging configuration: https://github.com/grafana/mimir/blob/50d1c27b4ad82b265ff5a865345bec2d726f64ef/pkg/util/log/log.go#L45-L46
"default logger": func(w io.Writer) log.Logger {
logger := dskit_log.NewGoKitWithWriter("logfmt", w)
logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", SpanLoggerAwareCaller(5))
logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", Caller(5))
logger = level.NewFilter(logger, level.AllowAll())
return logger
},

// This is based on Mimir's logging configuration with rate-limiting enabled: https://github.com/grafana/mimir/blob/50d1c27b4ad82b265ff5a865345bec2d726f64ef/pkg/util/log/log.go#L42-L43
"rate-limited logger": func(w io.Writer) log.Logger {
logger := dskit_log.NewGoKitWithWriter("logfmt", w)
logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", SpanLoggerAwareCaller(6))
logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", Caller(6))
logger = dskit_log.NewRateLimitedLogger(logger, 1000, 1000, nil)
logger = level.NewFilter(logger, level.AllowAll())
return logger
},

"default logger that has been wrapped with further information": func(w io.Writer) log.Logger {
logger := dskit_log.NewGoKitWithWriter("logfmt", w)
logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", SpanLoggerAwareCaller(5))
logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", Caller(5))
logger = level.NewFilter(logger, level.AllowAll())
logger = log.With(logger, "user", "user-1")
return logger
Expand Down

0 comments on commit 2c3d911

Please sign in to comment.