1
0

Compare commits

..

2 Commits

2 changed files with 44 additions and 26 deletions

View File

@ -12,6 +12,7 @@ import (
"math/rand" "math/rand"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"strings" "strings"
"time" "time"
@ -90,6 +91,8 @@ type PewCmd struct {
OutputOnSuccess bool `help:"show output on success"` OutputOnSuccess bool `help:"show output on success"`
RealtimeOutput bool `help:"show realtime output"` RealtimeOutput bool `help:"show realtime output"`
LogDir string `help:"write logs to directory"`
Endless bool `help:"endless tests"` Endless bool `help:"endless tests"`
EndlessTimeout time.Duration `help:"timeout between tests" default:"1m"` EndlessTimeout time.Duration `help:"timeout between tests" default:"1m"`
EndlessStress string `help:"endless stress script" type:"existingfile"` EndlessStress string `help:"endless stress script" type:"existingfile"`
@ -403,39 +406,54 @@ func (cmd PewCmd) testArtifact(swg *sizedwaitgroup.SizedWaitGroup,
defer swg.Done() defer swg.Done()
logdir := "logs/" + cmd.Tag var logDirWriter *zerolog.ConsoleWriter
err := os.MkdirAll(logdir, os.ModePerm) if cmd.LogDir != "" {
if err != nil { logdir := filepath.Join(cmd.LogDir, cmd.Tag)
log.Error().Err(err).Msgf("mkdir %s", logdir) err := os.MkdirAll(logdir, os.ModePerm)
return if err != nil {
} log.Error().Err(err).Msgf("mkdir %s", logdir)
return
}
logfile := fmt.Sprintf("logs/%s/%s-%s-%s.log", logfile := fmt.Sprintf("logs/%s/%s-%s-%s.log",
cmd.Tag, cmd.Tag,
ki.Distro.ID.String(), ki.Distro.ID.String(),
ki.Distro.Release, ki.Distro.Release,
ki.KernelRelease, ki.KernelRelease,
) )
f, err := os.Create(logfile) f, err := os.Create(logfile)
if err != nil { if err != nil {
log.Error().Err(err).Msgf("create %s", logfile) log.Error().Err(err).Msgf("create %s", logfile)
return return
} }
defer f.Close() defer f.Close()
slog := zerolog.New(zerolog.MultiLevelWriter( logDirWriter = &zerolog.ConsoleWriter{
&ConsoleWriter,
&FileWriter,
&zerolog.ConsoleWriter{
Out: f, Out: f,
FieldsExclude: []string{ FieldsExclude: []string{
"distro_release", "distro_release",
"distro_type", "distro_type",
"kernel", "kernel",
"command",
"workdir",
}, },
NoColor: true, NoColor: true,
}, }
)) }
var slog zerolog.Logger
if logDirWriter != nil {
slog = zerolog.New(zerolog.MultiLevelWriter(
&ConsoleWriter,
&FileWriter,
logDirWriter,
))
} else {
slog = zerolog.New(zerolog.MultiLevelWriter(
&ConsoleWriter,
&FileWriter,
))
}
switch LogLevel { switch LogLevel {
case zerolog.TraceLevel, zerolog.DebugLevel: case zerolog.TraceLevel, zerolog.DebugLevel:

View File

@ -466,7 +466,7 @@ func (c Container) build(imagePath string) (output string, err error) {
return return
} }
func (c Container) Run(workdir string, cmds []string) (out string, err error) { func (c *Container) Run(workdir string, cmds []string) (out string, err error) {
flog := c.Log.With(). flog := c.Log.With().
Str("workdir", workdir). Str("workdir", workdir).
Str("command", fmt.Sprintf("%v", cmds)). Str("command", fmt.Sprintf("%v", cmds)).
@ -535,7 +535,7 @@ func (c Container) Run(workdir string, cmds []string) (out string, err error) {
} }
c.handleCommandsOutput(m) c.handleCommandsOutput(m)
out += m + "\n" out += m + "\n"
flog.Trace().Str("stdout", m).Msg("") flog.Trace().Str("container stdout", m).Msg("")
} }
}() }()