Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
panics should show up in the log file when the --log option is enabled,
Browse files Browse the repository at this point in the history
closes #48
  • Loading branch information
nikhilsaraf committed Nov 9, 2018
1 parent 8e6fae2 commit bbad964
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"net/http"
"os"
"runtime/debug"
"strings"
"time"

Expand Down Expand Up @@ -43,6 +44,13 @@ func hiddenFlag(flag string) {
}
}

func logPanic() {
if r := recover(); r != nil {
st := debug.Stack()
log.Printf("PANIC!! recovered to log it in the file\npanic: %v\n\n%s\n", r, string(st))
}
}

func init() {
// short flags
botConfigPath := tradeCmd.Flags().StringP("botConf", "c", "", "(required) trading bot's basic config file path")
Expand Down Expand Up @@ -78,6 +86,9 @@ func init() {
return
}
log.Printf("logging to file: %s", fileName)

// we want to create a deferred recovery function here that will log panics to the log file and then exit
defer logPanic()
}

startupMessage := "Starting Kelp Trader: " + version + " [" + gitHash + "]"
Expand Down

0 comments on commit bbad964

Please sign in to comment.