Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/utils/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions t/01_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
Expand Down