diff --git a/pkg/utils/context.go b/pkg/utils/context.go index 408f4963..69d1e2e4 100644 --- a/pkg/utils/context.go +++ b/pkg/utils/context.go @@ -8,9 +8,14 @@ import ( type loggerCtxKey struct{} -//nolint:ireturn // context helpers must return context.Context by convention +const ( + loggerCtxKey2 string = "github.com/consol-monitoring/snclient/pkg/utils.Logger" +) + +//nolint:ireturn,staticcheck,revive,lll // context helpers must return context.Context by convention . If the context is used in a package that does not have access to loggerCtxKey, it can use the loggerCtxKey2 func ContextWithLogger(ctx context.Context, log *factorlog.FactorLog) context.Context { - return context.WithValue(ctx, loggerCtxKey{}, log) + return context.WithValue(context.WithValue(ctx, loggerCtxKey{}, log), + loggerCtxKey2, log) } func LoggerFromContext(ctx context.Context) *factorlog.FactorLog { diff --git a/t/01_cmd_test.go b/t/01_cmd_test.go index fd1d01b3..c94acf5a 100644 --- a/t/01_cmd_test.go +++ b/t/01_cmd_test.go @@ -52,9 +52,9 @@ func TestCommandFlags(t *testing.T) { runCmd(t, &cmd{ Cmd: bin, - Args: []string{"-vv", "run", "check_http", "-H", "localhost", "-p", "60666", "--uri=/test"}, - Like: []string{`HTTP CRITICAL`, `command: check_http`}, - ErrLike: []string{`GET`}, + Args: []string{"-v", "run", "check_http", "-H", "localhost", "-p", "60666", "--uri=/test"}, + Like: []string{`HTTP CRITICAL`}, + ErrLike: []string{``}, Exit: 2, }) }