- Notifications
You must be signed in to change notification settings - Fork18
feat: write agent output to a temporary file#422
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,6 +4,7 @@ import ( | ||
"net/url" | ||
"os" | ||
"os/signal" | ||
"path/filepath" | ||
"syscall" | ||
// We use slog here since agent runs in the background and we can benefit | ||
@@ -48,10 +49,20 @@ coder agent start | ||
coder agent start --coder-url https://my-coder.com --token xxxx-xxxx | ||
`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
sinks := []slog.Sink{ | ||
sloghuman.Sink(os.Stderr), | ||
} | ||
file, err := os.OpenFile(filepath.Join(os.TempDir(), "coder-agent.log"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) | ||
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. it didn't seem like the file we write needs to be hidden, so I made it a not-dotfile 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. Should be consistent for the other log files in that case 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. Which other log files do we have? I think just a code-server one right? 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. code-server and envagent, they're in environment_stages.go | ||
if err == nil && file != nil { | ||
sinks = append(sinks, sloghuman.Sink(file)) | ||
} | ||
log := slog.Make(sinks...).Leveled(slog.LevelDebug) | ||
if err != nil { | ||
log.Info(ctx, "failed to open agent log file", slog.Error(err)) | ||
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. Should this be an 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. maybe, but I don't expect it to happen for coder workspaces and everything would be logged to our console anyways | ||
} | ||
if coderURL == "" { | ||
var ok bool | ||
coderURL, ok = os.LookupEnv("CODER_URL") | ||