Skip to content

hotfix(agent): only retain 1 logfile at a time #7815

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

Merged
merged 2 commits into from
Jun 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
logWriter := &lumberjack.Logger{
Filename: filepath.Join(logDir, "coder-agent-init.log"),
MaxSize: 5, // MB
// Without this, rotated logs will never be deleted.
MaxBackups: 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is to avoid gigabytes of logs in /tmp? Perhaps a comment for posterity and to avoid regressions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it correctly rotates logs at 5mb but it leaves the old logs around forever without this.

}
defer logWriter.Close()

Expand Down Expand Up @@ -146,6 +148,8 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
ljLogger := &lumberjack.Logger{
Filename: filepath.Join(logDir, "coder-agent.log"),
MaxSize: 5, // MB
// Without this, rotated logs will never be deleted.
MaxBackups: 1,
}
defer ljLogger.Close()
logWriter := &closeWriter{w: ljLogger}
Expand Down