Skip to content

Commit

Permalink
Log stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
gertjaap committed Nov 10, 2020
1 parent 03f35a4 commit 522e6e6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"path/filepath"
"runtime/debug"

"github.com/leaanthony/mewn"
"github.com/marcsauter/single"
Expand All @@ -19,19 +20,20 @@ import (
func main() {
defer func() {
if err := recover(); err != nil {
tracking.Track(tracking.TrackingRequest{
Category: "Lifecycle",
Action: "Crash",
Name: fmt.Sprintf("%v", err),
})

// Reopen log file, since it's closed now!
logging.SetLogLevel(int(logging.LogLevelDebug))
logFilePath := filepath.Join(util.DataDirectory(), "debug.log")
logFile, _ := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
logging.SetLogFile(logFile)
defer logFile.Close()
log.Println(err)
logging.Errorf("%v\n%s\n", err, string(debug.Stack()))

tracking.Track(tracking.TrackingRequest{
Category: "Lifecycle",
Action: "Crash",
Name: fmt.Sprintf("%v", err),
})

}
}()

Expand Down

0 comments on commit 522e6e6

Please sign in to comment.