env.walk: inject contextual logging information

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-01-13 18:11:46 -08:00
parent e09723861f
commit f8a2109aba

View File

@ -82,14 +82,8 @@ func NewEnv(ctx context.Context, s Solver, bootsrc, inputsrc string) (*Env, erro
// Compute missing values in env configuration, and write them to state. // Compute missing values in env configuration, and write them to state.
func (env *Env) Compute(ctx context.Context) error { func (env *Env) Compute(ctx context.Context) error {
lg := log.Ctx(ctx) output, err := env.Walk(ctx, func(ctx context.Context, c *Component, out Fillable) error {
lg := log.Ctx(ctx)
output, err := env.Walk(ctx, func(c *Component, out Fillable) error {
lg := lg.
With().
Str("path", c.Value().Path().String()).
Logger()
ctx := lg.WithContext(ctx)
lg. lg.
Debug(). Debug().
@ -120,7 +114,7 @@ func (env *Env) Export(fs FS) (FS, error) {
return fs, nil return fs, nil
} }
type EnvWalkFunc func(*Component, Fillable) error type EnvWalkFunc func(context.Context, *Component, Fillable) error
// Walk components and return any computed values // Walk components and return any computed values
func (env *Env) Walk(ctx context.Context, fn EnvWalkFunc) (*Value, error) { func (env *Env) Walk(ctx context.Context, fn EnvWalkFunc) (*Value, error) {
@ -138,7 +132,7 @@ func (env *Env) Walk(ctx context.Context, fn EnvWalkFunc) (*Value, error) {
Str("value", env.cc.Wrap(flowInst.Value(), flowInst).JSON().String()). Str("value", env.cc.Wrap(flowInst.Value(), flowInst).JSON().String()).
Msg("walking") Msg("walking")
// Initialize empty output // Initialize empty output
out, err := env.cc.EmptyStruct() out, err := env.cc.EmptyStruct()
if err != nil { if err != nil {
return nil, err return nil, err
@ -162,9 +156,7 @@ func (env *Env) Walk(ctx context.Context, fn EnvWalkFunc) (*Value, error) {
Str("state", t.State().String()). Str("state", t.State().String()).
Logger() Logger()
lg. lg.Debug().Msg("cueflow task")
Debug().
Msg("cueflow task")
if t.State() != cueflow.Terminated { if t.State() != cueflow.Terminated {
return nil return nil
} }
@ -189,6 +181,7 @@ func (env *Env) Walk(ctx context.Context, fn EnvWalkFunc) (*Value, error) {
With(). With().
Str("path", v.Path().String()). Str("path", v.Path().String()).
Logger() Logger()
ctx := lg.WithContext(ctx)
lg.Debug().Msg("Env.Walk: processing") lg.Debug().Msg("Env.Walk: processing")
val := env.cc.Wrap(v, flowInst) val := env.cc.Wrap(v, flowInst)
@ -204,7 +197,7 @@ func (env *Env) Walk(ctx context.Context, fn EnvWalkFunc) (*Value, error) {
l.Lock() l.Lock()
defer l.Unlock() defer l.Unlock()
return fn(c, t) return fn(ctx, c, t)
}), nil }), nil
} }
// Orchestrate execution with cueflow // Orchestrate execution with cueflow