engine: Improve logging for resources and exec
This makes things a bit clearer and fixes some silly formatting bugs.
This commit is contained in:
@@ -243,7 +243,7 @@ func (obj *State) Init() error {
|
|||||||
|
|
||||||
Debug: obj.Debug,
|
Debug: obj.Debug,
|
||||||
Logf: func(format string, v ...interface{}) {
|
Logf: func(format string, v ...interface{}) {
|
||||||
obj.Logf("resource: "+format, v...)
|
obj.Logf(format, v...)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -253,10 +253,10 @@ func (obj *ExecRes) Watch(ctx context.Context) error {
|
|||||||
|
|
||||||
// each time we get a line of output, we loop!
|
// each time we get a line of output, we loop!
|
||||||
if s := data.text; s == "" {
|
if s := data.text; s == "" {
|
||||||
obj.init.Logf("watch output is empty!")
|
obj.init.Logf("watch out empty!")
|
||||||
} else {
|
} else {
|
||||||
obj.init.Logf("watch output is:")
|
obj.init.Logf("watch out:")
|
||||||
obj.init.Logf(s)
|
obj.init.Logf("%s", s)
|
||||||
}
|
}
|
||||||
if data.text != "" {
|
if data.text != "" {
|
||||||
send = true
|
send = true
|
||||||
@@ -335,18 +335,18 @@ func (obj *ExecRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
|||||||
|
|
||||||
obj.init.Logf("ifcmd exited with: %d", exitStatus)
|
obj.init.Logf("ifcmd exited with: %d", exitStatus)
|
||||||
if s := out.String(); s == "" {
|
if s := out.String(); s == "" {
|
||||||
obj.init.Logf("ifcmd output is empty!")
|
obj.init.Logf("ifcmd out empty!")
|
||||||
} else {
|
} else {
|
||||||
obj.init.Logf("ifcmd output is:")
|
obj.init.Logf("ifcmd out:")
|
||||||
obj.init.Logf(s)
|
obj.init.Logf("%s", s)
|
||||||
}
|
}
|
||||||
return true, nil // don't run
|
return true, nil // don't run
|
||||||
}
|
}
|
||||||
if s := out.String(); s == "" {
|
if s := out.String(); s == "" {
|
||||||
obj.init.Logf("ifcmd output is empty!")
|
obj.init.Logf("ifcmd out empty!")
|
||||||
} else {
|
} else {
|
||||||
obj.init.Logf("ifcmd output is:")
|
obj.init.Logf("ifcmd out:")
|
||||||
obj.init.Logf(s)
|
obj.init.Logf("%s", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,6 +422,7 @@ func (obj *ExecRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
|||||||
cmd.Stdout = out.Stdout
|
cmd.Stdout = out.Stdout
|
||||||
cmd.Stderr = out.Stderr
|
cmd.Stderr = out.Stderr
|
||||||
|
|
||||||
|
obj.init.Logf("cmd: %s", strings.Join(cmd.Args, " "))
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "error starting cmd")
|
return false, errwrap.Wrapf(err, "error starting cmd")
|
||||||
}
|
}
|
||||||
@@ -464,7 +465,14 @@ func (obj *ExecRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
|||||||
}
|
}
|
||||||
exitStatus := wStatus.ExitStatus()
|
exitStatus := wStatus.ExitStatus()
|
||||||
if !wStatus.Signaled() { // not a timeout or cancel (no signal)
|
if !wStatus.Signaled() { // not a timeout or cancel (no signal)
|
||||||
return false, errwrap.Wrapf(err, "cmd error, exit status: %d", exitStatus)
|
// most commands error in this way
|
||||||
|
if s := out.String(); s == "" {
|
||||||
|
obj.init.Logf("exit status %d", exitStatus)
|
||||||
|
} else {
|
||||||
|
obj.init.Logf("cmd error: %s", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, errwrap.Wrapf(err, "cmd error") // exit status will be in the error
|
||||||
}
|
}
|
||||||
sig := wStatus.Signal()
|
sig := wStatus.Signal()
|
||||||
|
|
||||||
@@ -483,10 +491,11 @@ func (obj *ExecRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
|||||||
// would be nice, but it would require terminal log output that doesn't
|
// would be nice, but it would require terminal log output that doesn't
|
||||||
// interleave all the parallel parts which would mix it all up...
|
// interleave all the parallel parts which would mix it all up...
|
||||||
if s := out.String(); s == "" {
|
if s := out.String(); s == "" {
|
||||||
obj.init.Logf("command output is empty!")
|
obj.init.Logf("cmd out empty!")
|
||||||
} else {
|
} else {
|
||||||
obj.init.Logf("command output is:")
|
obj.init.Logf("cmd out:")
|
||||||
obj.init.Logf(s)
|
obj.init.Logf("%s", s)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := obj.init.Send(&ExecSends{
|
if err := obj.init.Send(&ExecSends{
|
||||||
|
|||||||
Reference in New Issue
Block a user