From 5fc2139e0ecca0abc388600432b8c5fdb1b8cd28 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 2 Oct 2023 13:16:39 +0300 Subject: [PATCH] Use timestamp instead of unique ids for logging output data --- cli/executor/executor.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/cli/executor/executor.go b/cli/executor/executor.go index f06c6690..c32f53c3 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -10,7 +10,6 @@ package executor import ( "crypto/tls" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -20,7 +19,6 @@ import ( "github.com/essentialkaos/ek/v12/errutil" "github.com/essentialkaos/ek/v12/fsutil" "github.com/essentialkaos/ek/v12/log" - "github.com/essentialkaos/ek/v12/passwd" "github.com/essentialkaos/ek/v12/req" "github.com/essentialkaos/ek/v12/sliceutil" "github.com/essentialkaos/ek/v12/strutil" @@ -470,7 +468,7 @@ func skipCommand(c *recipe.Command, tags []string, lastSkippedGroupID uint8, fin return !sliceutil.Contains(tags, c.Tag) && !sliceutil.Contains(tags, "*") } -// logError logs error data +// logError saves output data into a file func logError(e *Executor, c *recipe.Command, a *recipe.Action, ce *CommandEnv, err error) { if e.config.ErrsDir == "" { return @@ -487,14 +485,14 @@ func logError(e *Executor, c *recipe.Command, a *recipe.Action, ce *CommandEnv, } } - id := passwd.GenPassword(8, passwd.STRENGTH_MEDIUM) - origin := getErrorOrigin(c, a, id) + ts := time.Now().UnixMicro() + origin := getErrorOrigin(c, a, ts) e.logger.Info("(%s) %v", origin, err) if ce != nil && !ce.output.IsEmpty() { - output := fmt.Sprintf("%s-output-%s.log", recipeName, id) - err := ioutil.WriteFile(fmt.Sprintf("%s/%s", e.config.ErrsDir, output), ce.output.Bytes(), 0644) + output := fmt.Sprintf("%s-output-%d.log", recipeName, ts) + err := os.WriteFile(fmt.Sprintf("%s/%s", e.config.ErrsDir, output), ce.output.Bytes(), 0644) if err != nil { e.logger.Info("(%s) Can't save output data: %v", origin, err) @@ -503,17 +501,17 @@ func logError(e *Executor, c *recipe.Command, a *recipe.Action, ce *CommandEnv, } // getErrorOrigin returns info about error origin -func getErrorOrigin(c *recipe.Command, a *recipe.Action, id string) string { +func getErrorOrigin(c *recipe.Command, a *recipe.Action, ts int64) string { switch a { case nil: return fmt.Sprintf( - "id: %s | command: %d | line: %d", - id, c.Index()+1, c.Line, + "ts: %d | command: %d | line: %d", + ts, c.Index()+1, c.Line, ) default: return fmt.Sprintf( - "id: %s | command: %d | action: %d:%s | line: %d", - id, c.Index()+1, a.Index()+1, a.Name, a.Line, + "ts: %d | command: %d | action: %d:%s | line: %d", + ts, c.Index()+1, a.Index()+1, a.Name, a.Line, ) } }