Commit 83bb9c90 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Added helpers to pass Loggers through context.Context.

No related merge requests found
Showing with 18 additions and 0 deletions
+18 -0
package log
import "context"
type loggerContextKeyType int
const loggerContextKey loggerContextKeyType = 0
func WithLogger(ctx context.Context, logger RawLogger) context.Context {
return context.WithValue(ctx, loggerContextKey, logger)
}
func FromContext(ctx context.Context) *Logger {
if logger, ok := ctx.Value(loggerContextKey).(RawLogger); ok {
return &Logger{logger}
}
return DefaultLogger
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment