feat: add step name to logger field (#1027)
* feat: add step name to logger field This change does add the step name to the logger fields. This does not change the output for our users, but for the json logger, it does make each step output traceable. * fix: remove new logger Since logrus and context both are immutable for our case, we can just add a new field and store the logger in the context. Co-authored-by: Casey Lee <cplee@nektos.com> Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
This commit is contained in:
parent
aab2af0919
commit
6b059572ff
|
@ -37,15 +37,18 @@ func newJobExecutor(info jobInfo) common.Executor {
|
||||||
}
|
}
|
||||||
stepExec := info.newStepExecutor(step)
|
stepExec := info.newStepExecutor(step)
|
||||||
steps = append(steps, func(ctx context.Context) error {
|
steps = append(steps, func(ctx context.Context) error {
|
||||||
err := stepExec(ctx)
|
stepName := step.String()
|
||||||
if err != nil {
|
return (func(ctx context.Context) error {
|
||||||
common.Logger(ctx).Errorf("%v", err)
|
err := stepExec(ctx)
|
||||||
common.SetJobError(ctx, err)
|
if err != nil {
|
||||||
} else if ctx.Err() != nil {
|
common.Logger(ctx).Errorf("%v", err)
|
||||||
common.Logger(ctx).Errorf("%v", ctx.Err())
|
common.SetJobError(ctx, err)
|
||||||
common.SetJobError(ctx, ctx.Err())
|
} else if ctx.Err() != nil {
|
||||||
}
|
common.Logger(ctx).Errorf("%v", ctx.Err())
|
||||||
return nil
|
common.SetJobError(ctx, ctx.Err())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})(withStepLogger(ctx, stepName))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,11 @@ func WithJobLogger(ctx context.Context, jobName string, config *Config, masks *[
|
||||||
return common.WithLogger(ctx, rtn)
|
return common.WithLogger(ctx, rtn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func withStepLogger(ctx context.Context, stepName string) context.Context {
|
||||||
|
rtn := common.Logger(ctx).WithFields(logrus.Fields{"step": stepName})
|
||||||
|
return common.WithLogger(ctx, rtn)
|
||||||
|
}
|
||||||
|
|
||||||
type entryProcessor func(entry *logrus.Entry) *logrus.Entry
|
type entryProcessor func(entry *logrus.Entry) *logrus.Entry
|
||||||
|
|
||||||
func valueMasker(insecureSecrets bool, secrets map[string]string, masks *[]string) entryProcessor {
|
func valueMasker(insecureSecrets bool, secrets map[string]string, masks *[]string) entryProcessor {
|
||||||
|
|
Loading…
Reference in New Issue