mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 04:27:37 +03:00
Fix staticcheck's SA1029
This commit is contained in:
parent
5ce3135f00
commit
f8362a4acb
19 changed files with 152 additions and 57 deletions
|
@ -24,6 +24,10 @@ const (
|
|||
LevelTrace = Level(logrus.TraceLevel)
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
const loggerCtxKey = contextKey("logger")
|
||||
|
||||
var (
|
||||
currentLevel Level
|
||||
defaultLogger = logrus.New()
|
||||
|
@ -66,7 +70,7 @@ func NewContext(ctx context.Context, keyValuePairs ...interface{}) context.Conte
|
|||
}
|
||||
|
||||
logger := addFields(createNewLogger(), keyValuePairs)
|
||||
ctx = context.WithValue(ctx, "logger", logger)
|
||||
ctx = context.WithValue(ctx, loggerCtxKey, logger)
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
@ -176,7 +180,7 @@ func extractLogger(ctx interface{}) (*logrus.Entry, error) {
|
|||
case *logrus.Entry:
|
||||
return ctx, nil
|
||||
case context.Context:
|
||||
logger := ctx.Value("logger")
|
||||
logger := ctx.Value(loggerCtxKey)
|
||||
if logger != nil {
|
||||
return logger.(*logrus.Entry), nil
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ var _ = Describe("Logger", func() {
|
|||
It("returns the logger from context if it has one", func() {
|
||||
logger := logrus.NewEntry(logrus.New())
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "logger", logger)
|
||||
ctx = context.WithValue(ctx, loggerCtxKey, logger)
|
||||
|
||||
Expect(extractLogger(ctx)).To(Equal(logger))
|
||||
})
|
||||
|
@ -144,7 +144,7 @@ var _ = Describe("Logger", func() {
|
|||
It("returns the logger from request's context if it has one", func() {
|
||||
logger := logrus.NewEntry(logrus.New())
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "logger", logger)
|
||||
ctx = context.WithValue(ctx, loggerCtxKey, logger)
|
||||
req := httptest.NewRequest("get", "/", nil).WithContext(ctx)
|
||||
|
||||
Expect(extractLogger(req)).To(Equal(logger))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue