diff --git a/context.go b/context.go index 1365f1c..97778b0 100644 --- a/context.go +++ b/context.go @@ -4,19 +4,20 @@ import "context" // WithContext wraps the given logger in context. func WithContext(ctx context.Context, logger *Logger) context.Context { - return context.WithValue(ctx, loggerContextKey, logger) + return context.WithValue(ctx, ContextKey, logger) } // FromContext returns the logger from the given context. // This will return the default package logger if no logger // found in context. func FromContext(ctx context.Context) *Logger { - if logger, ok := ctx.Value(loggerContextKey).(*Logger); ok { + if logger, ok := ctx.Value(ContextKey).(*Logger); ok { return logger } return defaultLogger } -type contextKey struct{} +type contextKey struct{ string } -var loggerContextKey = contextKey{} +// ContextKey is the key used to store the logger in context. +var ContextKey = contextKey{"log"}