Skip to content

Commit

Permalink
Merge pull request #58 from Alkorin/panic
Browse files Browse the repository at this point in the history
Try to catch panics to write them into webinc.log
  • Loading branch information
Alkorin authored Feb 8, 2019
2 parents d140f57 + e725bc4 commit 12b2f78
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"os"
"runtime/debug"

"github.com/ovh/configstore"
log "github.com/sirupsen/logrus"
Expand All @@ -14,8 +15,14 @@ func init() {
}

func main() {
log.Infof("Starting webinc version %q", buildVersion)
// Catch panics and try to log them into error file
defer func() {
if err := recover(); err != nil {
log.WithField("error", err).WithField("stack", string(debug.Stack())).Panic("Code paniced :(")
}
}()

log.Infof("Starting webinc version %q", buildVersion)
file, err := os.OpenFile("webinc.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 12b2f78

Please sign in to comment.