mirror of
https://github.com/compute-blade-community/compute-blade-agent.git
synced 2026-04-21 17:45:43 +02:00
23 lines
412 B
Go
23 lines
412 B
Go
package log
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type logCtxKey int
|
|
|
|
func IntoContext(ctx context.Context, logger *zap.Logger) context.Context {
|
|
return context.WithValue(ctx, logCtxKey(0), logger)
|
|
}
|
|
|
|
func FromContext(ctx context.Context) *zap.Logger {
|
|
val := ctx.Value(logCtxKey(0))
|
|
if val != nil {
|
|
return val.(*zap.Logger)
|
|
}
|
|
zap.L().Warn("No logger in context, passing default")
|
|
return zap.L()
|
|
}
|