Skip to content

Commit

Permalink
fix(logctx): fallback interface conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Jun 12, 2024
1 parent 26bad55 commit 9241d65
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/logctx/logctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import (
type ctxKey struct{}

func From(ctx context.Context) *zap.Logger {
return ctx.Value(ctxKey{}).(*zap.Logger)
if l, ok := ctx.Value(ctxKey{}).(*zap.Logger); ok {
return l
}
return zap.NewNop()
}

func With(ctx context.Context, logger *zap.Logger) context.Context {
Expand Down

0 comments on commit 9241d65

Please sign in to comment.