simplify how we log commands

This commit is contained in:
Jesse Duffield 2022-01-05 11:57:32 +11:00
parent e524e39842
commit 05fa483f48
44 changed files with 291 additions and 233 deletions

View file

@ -87,22 +87,6 @@ func NewOSCommand(common *common.Common, platform *Platform) *OSCommand {
return c
}
func (c *OSCommand) WithSpan(span string) *OSCommand {
// sometimes .WithSpan(span) will be called where span actually is empty, in
// which case we don't need to log anything so we can just return early here
// with the original struct
if span == "" {
return c
}
newOSCommand := &OSCommand{}
*newOSCommand = *c
newOSCommand.CmdLogSpan = span
newOSCommand.Cmd.logCmdObj = newOSCommand.LogCmdObj
newOSCommand.Cmd.runner = &cmdObjRunner{log: c.Log, logCmdObj: newOSCommand.LogCmdObj}
return newOSCommand
}
func (c *OSCommand) LogCmdObj(cmdObj ICmdObj) {
c.LogCommand(cmdObj.ToString(), true)
}
@ -110,7 +94,7 @@ func (c *OSCommand) LogCmdObj(cmdObj ICmdObj) {
func (c *OSCommand) LogCommand(cmdStr string, commandLine bool) {
c.Log.WithField("command", cmdStr).Info("RunCommand")
if c.onRunCommand != nil && c.CmdLogSpan != "" {
if c.onRunCommand != nil {
c.onRunCommand(NewCmdLogEntry(cmdStr, c.CmdLogSpan, commandLine))
}
}