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

Standardize how we log and handle panics #1692

Merged
16 changes: 16 additions & 0 deletions cmd/launcher/svc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@ func (w *winSvc) Execute(args []string, r <-chan svc.ChangeRequest, changes chan
ctx = ctxlog.NewContext(ctx, w.logger)

go func() {
// Log panics from runLauncher
defer func() {
if r := recover(); r != nil {
w.systemSlogger.Log(context.TODO(), slog.LevelInfo,
"panic occurred in runLauncher",
"err", r,
)
if err, ok := r.(error); ok {
w.systemSlogger.Log(context.TODO(), slog.LevelInfo,
"panic stack trace",
"stack_trace", fmt.Sprintf("%+v", errors.WithStack(err)),
)
}
}
}()

err := runLauncher(ctx, cancel, w.slogger, w.systemSlogger, w.opts)
if err != nil {
w.systemSlogger.Log(ctx, slog.LevelInfo,
Expand Down
Loading