Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--log-output=file does not always flush all logs to the file after k6 is done #2413

Closed
na-- opened this issue Mar 7, 2022 · 0 comments · Fixed by #2414
Closed

--log-output=file does not always flush all logs to the file after k6 is done #2413

na-- opened this issue Mar 7, 2022 · 0 comments · Fixed by #2414
Assignees
Labels
Milestone

Comments

@na--
Copy link
Member

na-- commented Mar 7, 2022

We don't have the same "done" channel for file log outputs that we do for loki:

k6/cmd/root.go

Lines 292 to 309 in 1e28a3e

case strings.HasPrefix(line, "loki"):
ch = make(chan struct{})
hook, err := log.LokiFromConfigLine(c.ctx, c.fallbackLogger, line, ch)
if err != nil {
return nil, err
}
c.logger.AddHook(hook)
c.logger.SetOutput(ioutil.Discard) // don't output to anywhere else
c.logFmt = "raw"
case strings.HasPrefix(line, "file"):
hook, err := log.FileHookFromConfigLine(c.ctx, c.fallbackLogger, line)
if err != nil {
return nil, err
}
c.logger.AddHook(hook)
c.logger.SetOutput(ioutil.Discard)

So this code is not guaranteed to run:

k6/log/file.go

Lines 129 to 136 in 1e28a3e

case <-ctx.Done():
if err := h.bw.Flush(); err != nil {
h.fallbackLogger.Errorf("failed to flush buffer: %w", err)
}
if err := h.w.Close(); err != nil {
h.fallbackLogger.Errorf("failed to close logfile: %w", err)
}

I found this while writing some integration tests so I have a bugfix that I will submit shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants