- Notifications
You must be signed in to change notification settings - Fork1k
feat(cli): rotate file logs for coderd#15438
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4,11 +4,11 @@ import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"regexp" | ||
"strings" | ||
"golang.org/x/xerrors" | ||
"gopkg.in/natefinch/lumberjack.v2" | ||
"cdr.dev/slog" | ||
"cdr.dev/slog/sloggers/sloghuman" | ||
@@ -104,20 +104,21 @@ func (b *Builder) Build(inv *serpent.Invocation) (log slog.Logger, closeLog func | ||
addSinkIfProvided := func(sinkFn func(io.Writer) slog.Sink, loc string) error { | ||
switch loc { | ||
case "": | ||
case "/dev/stdout": | ||
sinks = append(sinks, sinkFn(inv.Stdout)) | ||
case "/dev/stderr": | ||
sinks = append(sinks, sinkFn(inv.Stderr)) | ||
default: | ||
logWriter := &lumberjack.Logger{ | ||
Filename: loc, | ||
MaxSize: 5, // MB | ||
// Without this, rotated logs will never be deleted. | ||
MaxBackups: 1, | ||
} | ||
closers = append(closers,logWriter.Close) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Does this give us the equivalent behaviour of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think we should probably re-use that same fix here, although the main reason for that seems to have been to reduce CI flakes due to racy writes after close. We probably won't be logging to a file in CI in the general case. | ||
sinks = append(sinks, sinkFn(logWriter)) | ||
} | ||
return nil | ||
} | ||
Uh oh!
There was an error while loading.Please reload this page.