From 177960431c255a87366a3dc0cd6e2ad96f022319 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Fri, 6 Oct 2023 14:23:29 -0700 Subject: [PATCH] Add some comments to pkg/loggerctx --- pkg/loggerctx/log.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/loggerctx/log.go b/pkg/loggerctx/log.go index 278e97f..b948530 100644 --- a/pkg/loggerctx/log.go +++ b/pkg/loggerctx/log.go @@ -6,12 +6,16 @@ import ( "go.elara.ws/logger" ) +// loggerCtxKey is used as the context key for loggers type loggerCtxKey struct{} +// With returns a copy of ctx containing log func With(ctx context.Context, log logger.Logger) context.Context { return context.WithValue(ctx, loggerCtxKey{}, log) } +// From attempts to get a logger from ctx. If ctx doesn't +// contain a logger, it returns a nop logger. func From(ctx context.Context) logger.Logger { if val := ctx.Value(loggerCtxKey{}); val != nil { if log, ok := val.(logger.Logger); ok && log != nil {