Skip to content

Commit

Permalink
Log stack trace for panic when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Jan 8, 2024
1 parent ed87ea2 commit f958490
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/kolide/launcher/pkg/log/locallogger"
"github.com/kolide/launcher/pkg/log/multislogger"
"github.com/kolide/launcher/pkg/log/teelogger"
"github.com/pkg/errors"
)

func main() {
Expand Down Expand Up @@ -131,6 +132,12 @@ func main() {
"msg", "panic occurred",
"err", r,
)
if err, ok := r.(error); ok {
level.Info(logger).Log(
"msg", "panic stack trace",
"stack_trace", fmt.Sprintf("%+v", errors.WithStack(err)),
)
}
time.Sleep(time.Second)
}
}()
Expand Down
7 changes: 7 additions & 0 deletions cmd/launcher/svc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/kolide/launcher/pkg/log/locallogger"
"github.com/kolide/launcher/pkg/log/multislogger"
"github.com/kolide/launcher/pkg/log/teelogger"
"github.com/pkg/errors"

"golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/debug"
Expand Down Expand Up @@ -115,6 +116,12 @@ func runWindowsSvc(args []string) error {
"msg", "panic occurred in windows service",
"err", r,
)
if err, ok := r.(error); ok {
level.Info(logger).Log(
"msg", "panic stack trace",
"stack_trace", fmt.Sprintf("%+v", errors.WithStack(err)),
)
}
time.Sleep(time.Second)
}
}()
Expand Down

0 comments on commit f958490

Please sign in to comment.