DEV 1666: Fix /end requests and clean up logging (#109)
* ensure /end request is always called, and refactor win/draw logic * clean up logging and error handling during initialization * automatically generate friendly snake names * title-case snake names * print out list of alive snake names instead of count * log snake names, IDs, and URLs at startup * print out state for turn zero
This commit is contained in:
parent
006f394355
commit
09aea9c49d
10 changed files with 317 additions and 151 deletions
|
|
@ -2,15 +2,18 @@ package commands
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
stdlog "log"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
log "github.com/spf13/jwalterweatherman"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var cfgFile string
|
||||
var verbose bool
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "battlesnake",
|
||||
|
|
@ -41,7 +44,7 @@ func init() {
|
|||
// will be global for your application.
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.battlesnake.yaml)")
|
||||
|
||||
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Enable debug logging")
|
||||
}
|
||||
|
||||
// initConfig reads in config file and ENV variables if set.
|
||||
|
|
@ -68,4 +71,13 @@ func initConfig() {
|
|||
if err := viper.ReadInConfig(); err == nil {
|
||||
fmt.Println("Using config file:", viper.ConfigFileUsed())
|
||||
}
|
||||
|
||||
// Setup logging
|
||||
log.SetStdoutOutput(os.Stderr)
|
||||
log.SetFlags(stdlog.Ltime | stdlog.Lmicroseconds)
|
||||
if verbose {
|
||||
log.SetStdoutThreshold(log.LevelDebug)
|
||||
} else {
|
||||
log.SetStdoutThreshold(log.LevelInfo)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue