From 7a811e6a81ee68362112d91f3c331874dae7b518 Mon Sep 17 00:00:00 2001 From: Reidmcc Date: Sun, 2 Dec 2018 16:18:45 -0600 Subject: [PATCH 1/7] Add loggers package, update trade.go --- cmd/trade.go | 73 ++++++++++++++++++++------------------ support/loggers/loggers.go | 53 +++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 35 deletions(-) create mode 100644 support/loggers/loggers.go diff --git a/cmd/trade.go b/cmd/trade.go index a4637c074..969b9af68 100644 --- a/cmd/trade.go +++ b/cmd/trade.go @@ -12,6 +12,7 @@ import ( "github.com/interstellar/kelp/model" "github.com/interstellar/kelp/plugins" + "github.com/interstellar/kelp/support/loggers" "github.com/interstellar/kelp/support/monitoring" "github.com/interstellar/kelp/support/networking" "github.com/interstellar/kelp/support/utils" @@ -31,6 +32,8 @@ var tradeCmd = &cobra.Command{ Example: tradeExamples, } +var logger loggers.BasicLogger + func requiredFlag(flag string) { e := tradeCmd.MarkFlagRequired(flag) if e != nil { @@ -48,7 +51,7 @@ 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)) + logger.Errorf("PANIC!! recovered to log it in the file\npanic: %v\n\n%s\n", r, string(st)) } } @@ -81,9 +84,9 @@ func init() { if *fixedIterations == 0 { fixedIterations = nil - log.Printf("will run unbounded iterations\n") + logger.Info("will run unbounded iterations") } else { - log.Printf("will run only %d update iterations\n", *fixedIterations) + logger.Infof("will run only %d update iterations\n", *fixedIterations) } } @@ -93,8 +96,8 @@ func init() { utils.CheckConfigError(botConfig, e, *botConfigPath) e = botConfig.Init() if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) } if *logPrefix != "" { @@ -102,11 +105,11 @@ func init() { fileName := fmt.Sprintf("%s_%s_%s_%s_%s_%s.log", *logPrefix, botConfig.AssetCodeA, botConfig.IssuerA, botConfig.AssetCodeB, botConfig.IssuerB, t) e = setLogFile(fileName) if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) return } - log.Printf("logging to file: %s", fileName) + logger.Infof("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() @@ -116,14 +119,14 @@ func init() { if *simMode { startupMessage += " (simulation mode)" } - log.Println(startupMessage) + logger.Info(startupMessage) // now that we've got the basic messages logged, validate the cli params validateCliParams() // only log botConfig file here so it can be included in the log file utils.LogConfig(botConfig) - log.Printf("Trading %s:%s for %s:%s\n", botConfig.AssetCodeA, botConfig.IssuerA, botConfig.AssetCodeB, botConfig.IssuerB) + logger.Infof("Trading %s:%s for %s:%s\n", botConfig.AssetCodeA, botConfig.IssuerA, botConfig.AssetCodeB, botConfig.IssuerB) client := &horizon.Client{ URL: botConfig.HorizonURL, @@ -132,7 +135,7 @@ func init() { alert, e := monitoring.MakeAlert(botConfig.AlertType, botConfig.AlertAPIKey) if e != nil { - log.Printf("Unable to set up monitoring for alert type '%s' with the given API key\n", botConfig.AlertType) + logger.Infof("Unable to set up monitoring for alert type '%s' with the given API key\n", botConfig.AlertType) } // --- start initialization of objects ---- threadTracker := multithreading.MakeThreadTracker() @@ -155,8 +158,8 @@ func init() { dataKey := model.MakeSortedBotKey(assetBase, assetQuote) strat, e := plugins.MakeStrategy(sdex, &assetBase, &assetQuote, *strategy, *stratConfigPath) if e != nil { - log.Println() - log.Println(e) + logger.Info("") + logger.Fatal(e) // we want to delete all the offers and exit here since there is something wrong with our setup deleteAllOffersAndExit(botConfig, client, sdex) } @@ -178,17 +181,17 @@ func init() { ) // --- end initialization of objects --- - log.Printf("validating trustlines...\n") + logger.Infof("validating trustlines...\n") validateTrustlines(client, &botConfig) - log.Printf("trustlines valid\n") + logger.Infof("trustlines valid\n") // --- start initialization of services --- if botConfig.MonitoringPort != 0 { go func() { e := startMonitoringServer(botConfig) if e != nil { - log.Println() - log.Printf("unable to start the monitoring server or problem encountered while running server: %s\n", e) + logger.Info("") + logger.Infof("unable to start the monitoring server or problem encountered while running server: %s\n", e) // we want to delete all the offers and exit here because we don't want the bot to run if monitoring isn't working // if monitoring is desired but not working properly, we want the bot to be shut down and guarantee that there // aren't outstanding offers. @@ -198,7 +201,7 @@ func init() { } // --- end initialization of services --- - log.Println("Starting the trader bot...") + logger.Info("Starting the trader bot...") bot.Start() } } @@ -237,15 +240,15 @@ func startMonitoringServer(botConfig trader.BotConfig) error { return fmt.Errorf("unable to initialize the metrics server: %s", e) } - log.Printf("Starting monitoring server on port %d\n", botConfig.MonitoringPort) + logger.Infof("Starting monitoring server on port %d\n", botConfig.MonitoringPort) return server.StartServer(botConfig.MonitoringPort, botConfig.MonitoringTLSCert, botConfig.MonitoringTLSKey) } func validateTrustlines(client *horizon.Client, botConfig *trader.BotConfig) { account, e := client.LoadAccount(botConfig.TradingAccount()) if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) } missingTrustlines := []string{} @@ -264,49 +267,49 @@ func validateTrustlines(client *horizon.Client, botConfig *trader.BotConfig) { } if len(missingTrustlines) > 0 { - log.Println() - log.Fatalf("error: your trading account does not have the required trustlines: %v\n", missingTrustlines) + logger.Info("") + logger.Fatalf("error: your trading account does not have the required trustlines: %v\n", missingTrustlines) } } func deleteAllOffersAndExit(botConfig trader.BotConfig, client *horizon.Client, sdex *plugins.SDEX) { - log.Println() - log.Printf("deleting all offers and then exiting...\n") + logger.Info("") + logger.Infof("deleting all offers and then exiting...\n") offers, e := utils.LoadAllOffers(botConfig.TradingAccount(), client) if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) return } sellingAOffers, buyingAOffers := utils.FilterOffers(offers, botConfig.AssetBase(), botConfig.AssetQuote()) allOffers := append(sellingAOffers, buyingAOffers...) dOps := sdex.DeleteAllOffers(allOffers) - log.Printf("created %d operations to delete offers\n", len(dOps)) + logger.Infof("created %d operations to delete offers\n", len(dOps)) if len(dOps) > 0 { e := sdex.SubmitOps(dOps, func(hash string, e error) { if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) return } - log.Fatal("...deleted all offers, exiting") + logger.Fatalf("...deleted all offers, exiting") }) if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) return } for { sleepSeconds := 10 - log.Printf("sleeping for %d seconds until our deletion is confirmed and we exit...\n", sleepSeconds) + logger.Infof("sleeping for %d seconds until our deletion is confirmed and we exit...\n", sleepSeconds) time.Sleep(time.Duration(sleepSeconds) * time.Second) } } else { - log.Fatal("...nothing to delete, exiting") + logger.Fatalf("...nothing to delete, exiting") } } diff --git a/support/loggers/loggers.go b/support/loggers/loggers.go new file mode 100644 index 000000000..fa748bd58 --- /dev/null +++ b/support/loggers/loggers.go @@ -0,0 +1,53 @@ +package loggers // I didn't call the packacke "logging" because the go-loggeing framework's package is "logging" so we'll need to be different when we switch + +import ( + "log" +) + +type Logger interface { + // basic messages, appends a newline (\n) after each entry + Info(msg string) + + // basic messages, can be custom formatted, similar to fmt.Printf. User needs to add a \n if they want a newline after the log entry + Infof(msg string, args ...interface{}) + + // error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. Appends a newline (\n) after each entry. + Error(msg string) + + // error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. User needs to add a \n if they want a newline after the log entry. + Errorf(msg string, args ...interface{}) + + // added Fatal and Fatalf because trade.go (and elsewhere) use log.Fatal + // fatal error messages, with newline + Fatal(e error) + + // formatted fatal error messages, without automatic newline + Fatalf(e error, args ...interface{}) +} + +type BasicLogger struct { +} + +func (l BasicLogger) Info(msg string) { + log.Println(msg) +} + +func (l BasicLogger) Infof(msg string, args ...interface{}) { + log.Printf(msg, args...) +} + +func (l BasicLogger) Error(msg string) { + log.Println(msg) // isn't actually differnt from Info until we do structured logs +} + +func (l BasicLogger) Errorf(msg string, args ...interface{}) { + log.Printf(msg, args...) // isn't actually differnt from Infof until we do structured logs +} + +func (l BasicLogger) Fatal(e error) { + log.Fatal(e) +} + +func (l BasicLogger) Fatalf(e string, args ...interface{}) { + log.Fatalf(e, args...) +} From 775878ec0e121b89565de857c47b971148216272 Mon Sep 17 00:00:00 2001 From: Reidmcc Date: Sun, 2 Dec 2018 16:18:45 -0600 Subject: [PATCH 2/7] Add loggers package, update trade.go --- cmd/trade.go | 73 ++++++++++++++++++++------------------ support/loggers/loggers.go | 53 +++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 35 deletions(-) create mode 100644 support/loggers/loggers.go diff --git a/cmd/trade.go b/cmd/trade.go index 303c6c27d..27957c75c 100644 --- a/cmd/trade.go +++ b/cmd/trade.go @@ -12,6 +12,7 @@ import ( "github.com/interstellar/kelp/model" "github.com/interstellar/kelp/plugins" + "github.com/interstellar/kelp/support/loggers" "github.com/interstellar/kelp/support/monitoring" "github.com/interstellar/kelp/support/networking" "github.com/interstellar/kelp/support/utils" @@ -31,6 +32,8 @@ var tradeCmd = &cobra.Command{ Example: tradeExamples, } +var logger loggers.BasicLogger + func requiredFlag(flag string) { e := tradeCmd.MarkFlagRequired(flag) if e != nil { @@ -48,7 +51,7 @@ 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)) + logger.Errorf("PANIC!! recovered to log it in the file\npanic: %v\n\n%s\n", r, string(st)) } } @@ -81,9 +84,9 @@ func init() { if *fixedIterations == 0 { fixedIterations = nil - log.Printf("will run unbounded iterations\n") + logger.Info("will run unbounded iterations") } else { - log.Printf("will run only %d update iterations\n", *fixedIterations) + logger.Infof("will run only %d update iterations\n", *fixedIterations) } } @@ -93,8 +96,8 @@ func init() { utils.CheckConfigError(botConfig, e, *botConfigPath) e = botConfig.Init() if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) } if *logPrefix != "" { @@ -102,11 +105,11 @@ func init() { fileName := fmt.Sprintf("%s_%s_%s_%s_%s_%s.log", *logPrefix, botConfig.AssetCodeA, botConfig.IssuerA, botConfig.AssetCodeB, botConfig.IssuerB, t) e = setLogFile(fileName) if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) return } - log.Printf("logging to file: %s", fileName) + logger.Infof("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() @@ -116,14 +119,14 @@ func init() { if *simMode { startupMessage += " (simulation mode)" } - log.Println(startupMessage) + logger.Info(startupMessage) // now that we've got the basic messages logged, validate the cli params validateCliParams() // only log botConfig file here so it can be included in the log file utils.LogConfig(botConfig) - log.Printf("Trading %s:%s for %s:%s\n", botConfig.AssetCodeA, botConfig.IssuerA, botConfig.AssetCodeB, botConfig.IssuerB) + logger.Infof("Trading %s:%s for %s:%s\n", botConfig.AssetCodeA, botConfig.IssuerA, botConfig.AssetCodeB, botConfig.IssuerB) client := &horizon.Client{ URL: botConfig.HorizonURL, @@ -132,7 +135,7 @@ func init() { alert, e := monitoring.MakeAlert(botConfig.AlertType, botConfig.AlertAPIKey) if e != nil { - log.Printf("Unable to set up monitoring for alert type '%s' with the given API key\n", botConfig.AlertType) + logger.Infof("Unable to set up monitoring for alert type '%s' with the given API key\n", botConfig.AlertType) } // --- start initialization of objects ---- threadTracker := multithreading.MakeThreadTracker() @@ -166,8 +169,8 @@ func init() { dataKey := model.MakeSortedBotKey(assetBase, assetQuote) strat, e := plugins.MakeStrategy(sdex, tradingPair, &assetBase, &assetQuote, *strategy, *stratConfigPath, *simMode) if e != nil { - log.Println() - log.Println(e) + logger.Info("") + logger.Fatal(e) // we want to delete all the offers and exit here since there is something wrong with our setup deleteAllOffersAndExit(botConfig, client, sdex) } @@ -189,17 +192,17 @@ func init() { ) // --- end initialization of objects --- - log.Printf("validating trustlines...\n") + logger.Infof("validating trustlines...\n") validateTrustlines(client, &botConfig) - log.Printf("trustlines valid\n") + logger.Infof("trustlines valid\n") // --- start initialization of services --- if botConfig.MonitoringPort != 0 { go func() { e := startMonitoringServer(botConfig) if e != nil { - log.Println() - log.Printf("unable to start the monitoring server or problem encountered while running server: %s\n", e) + logger.Info("") + logger.Infof("unable to start the monitoring server or problem encountered while running server: %s\n", e) // we want to delete all the offers and exit here because we don't want the bot to run if monitoring isn't working // if monitoring is desired but not working properly, we want the bot to be shut down and guarantee that there // aren't outstanding offers. @@ -242,7 +245,7 @@ func init() { } // --- end initialization of services --- - log.Println("Starting the trader bot...") + logger.Info("Starting the trader bot...") bot.Start() } } @@ -281,15 +284,15 @@ func startMonitoringServer(botConfig trader.BotConfig) error { return fmt.Errorf("unable to initialize the metrics server: %s", e) } - log.Printf("Starting monitoring server on port %d\n", botConfig.MonitoringPort) + logger.Infof("Starting monitoring server on port %d\n", botConfig.MonitoringPort) return server.StartServer(botConfig.MonitoringPort, botConfig.MonitoringTLSCert, botConfig.MonitoringTLSKey) } func validateTrustlines(client *horizon.Client, botConfig *trader.BotConfig) { account, e := client.LoadAccount(botConfig.TradingAccount()) if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) } missingTrustlines := []string{} @@ -308,49 +311,49 @@ func validateTrustlines(client *horizon.Client, botConfig *trader.BotConfig) { } if len(missingTrustlines) > 0 { - log.Println() - log.Fatalf("error: your trading account does not have the required trustlines: %v\n", missingTrustlines) + logger.Info("") + logger.Fatalf("error: your trading account does not have the required trustlines: %v\n", missingTrustlines) } } func deleteAllOffersAndExit(botConfig trader.BotConfig, client *horizon.Client, sdex *plugins.SDEX) { - log.Println() - log.Printf("deleting all offers and then exiting...\n") + logger.Info("") + logger.Infof("deleting all offers and then exiting...\n") offers, e := utils.LoadAllOffers(botConfig.TradingAccount(), client) if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) return } sellingAOffers, buyingAOffers := utils.FilterOffers(offers, botConfig.AssetBase(), botConfig.AssetQuote()) allOffers := append(sellingAOffers, buyingAOffers...) dOps := sdex.DeleteAllOffers(allOffers) - log.Printf("created %d operations to delete offers\n", len(dOps)) + logger.Infof("created %d operations to delete offers\n", len(dOps)) if len(dOps) > 0 { e := sdex.SubmitOps(dOps, func(hash string, e error) { if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) return } - log.Fatal("...deleted all offers, exiting") + logger.Fatalf("...deleted all offers, exiting") }) if e != nil { - log.Println() - log.Fatal(e) + logger.Info("") + logger.Fatal(e) return } for { sleepSeconds := 10 - log.Printf("sleeping for %d seconds until our deletion is confirmed and we exit...\n", sleepSeconds) + logger.Infof("sleeping for %d seconds until our deletion is confirmed and we exit...\n", sleepSeconds) time.Sleep(time.Duration(sleepSeconds) * time.Second) } } else { - log.Fatal("...nothing to delete, exiting") + logger.Fatalf("...nothing to delete, exiting") } } diff --git a/support/loggers/loggers.go b/support/loggers/loggers.go new file mode 100644 index 000000000..fa748bd58 --- /dev/null +++ b/support/loggers/loggers.go @@ -0,0 +1,53 @@ +package loggers // I didn't call the packacke "logging" because the go-loggeing framework's package is "logging" so we'll need to be different when we switch + +import ( + "log" +) + +type Logger interface { + // basic messages, appends a newline (\n) after each entry + Info(msg string) + + // basic messages, can be custom formatted, similar to fmt.Printf. User needs to add a \n if they want a newline after the log entry + Infof(msg string, args ...interface{}) + + // error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. Appends a newline (\n) after each entry. + Error(msg string) + + // error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. User needs to add a \n if they want a newline after the log entry. + Errorf(msg string, args ...interface{}) + + // added Fatal and Fatalf because trade.go (and elsewhere) use log.Fatal + // fatal error messages, with newline + Fatal(e error) + + // formatted fatal error messages, without automatic newline + Fatalf(e error, args ...interface{}) +} + +type BasicLogger struct { +} + +func (l BasicLogger) Info(msg string) { + log.Println(msg) +} + +func (l BasicLogger) Infof(msg string, args ...interface{}) { + log.Printf(msg, args...) +} + +func (l BasicLogger) Error(msg string) { + log.Println(msg) // isn't actually differnt from Info until we do structured logs +} + +func (l BasicLogger) Errorf(msg string, args ...interface{}) { + log.Printf(msg, args...) // isn't actually differnt from Infof until we do structured logs +} + +func (l BasicLogger) Fatal(e error) { + log.Fatal(e) +} + +func (l BasicLogger) Fatalf(e string, args ...interface{}) { + log.Fatalf(e, args...) +} From 3ba36adec51f336ce5441e0b2cc6624628de8ce5 Mon Sep 17 00:00:00 2001 From: Reidmcc Date: Thu, 3 Jan 2019 20:32:09 -0600 Subject: [PATCH 3/7] change funcs to unexported --- support/loggers/loggers.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/support/loggers/loggers.go b/support/loggers/loggers.go index fa748bd58..de0100c60 100644 --- a/support/loggers/loggers.go +++ b/support/loggers/loggers.go @@ -25,29 +25,29 @@ type Logger interface { Fatalf(e error, args ...interface{}) } -type BasicLogger struct { +type basicLogger struct { } -func (l BasicLogger) Info(msg string) { +func (l basicLogger) Info(msg string) { log.Println(msg) } -func (l BasicLogger) Infof(msg string, args ...interface{}) { +func (l basicLogger) Infof(msg string, args ...interface{}) { log.Printf(msg, args...) } -func (l BasicLogger) Error(msg string) { +func (l basicLogger) Error(msg string) { log.Println(msg) // isn't actually differnt from Info until we do structured logs } -func (l BasicLogger) Errorf(msg string, args ...interface{}) { +func (l basicLogger) Errorf(msg string, args ...interface{}) { log.Printf(msg, args...) // isn't actually differnt from Infof until we do structured logs } -func (l BasicLogger) Fatal(e error) { +func (l basicLogger) Fatal(e error) { log.Fatal(e) } -func (l BasicLogger) Fatalf(e string, args ...interface{}) { +func (l basicLogger) Fatalf(e string, args ...interface{}) { log.Fatalf(e, args...) } From e7e73bdc9499534705e94a4ab3ea4b5f9128fe00 Mon Sep 17 00:00:00 2001 From: Reidmcc Date: Thu, 10 Jan 2019 16:24:13 -0600 Subject: [PATCH 4/7] major rework --- cmd/trade.go | 88 +++++++++++++++++------------------ support/logger/basicLogger.go | 36 ++++++++++++++ support/logger/logger.go | 25 ++++++++++ support/loggers/loggers.go | 53 --------------------- 4 files changed, 105 insertions(+), 97 deletions(-) create mode 100644 support/logger/basicLogger.go create mode 100644 support/logger/logger.go delete mode 100644 support/loggers/loggers.go diff --git a/cmd/trade.go b/cmd/trade.go index 27957c75c..2720a2bc8 100644 --- a/cmd/trade.go +++ b/cmd/trade.go @@ -12,7 +12,7 @@ import ( "github.com/interstellar/kelp/model" "github.com/interstellar/kelp/plugins" - "github.com/interstellar/kelp/support/loggers" + "github.com/interstellar/kelp/support/logger" "github.com/interstellar/kelp/support/monitoring" "github.com/interstellar/kelp/support/networking" "github.com/interstellar/kelp/support/utils" @@ -32,7 +32,7 @@ var tradeCmd = &cobra.Command{ Example: tradeExamples, } -var logger loggers.BasicLogger +var l *logger.BasicLogger func requiredFlag(flag string) { e := tradeCmd.MarkFlagRequired(flag) @@ -51,7 +51,8 @@ func hiddenFlag(flag string) { func logPanic() { if r := recover(); r != nil { st := debug.Stack() - logger.Errorf("PANIC!! recovered to log it in the file\npanic: %v\n\n%s\n", r, string(st)) + l.Errorf("PANIC!! recovered to log it in the file\npanic: %v\n\n%s\n", r, string(st)) + os.Exit(1) } } @@ -84,9 +85,9 @@ func init() { if *fixedIterations == 0 { fixedIterations = nil - logger.Info("will run unbounded iterations") + l.Info("will run unbounded iterations") } else { - logger.Infof("will run only %d update iterations\n", *fixedIterations) + l.Infof("will run only %d update iterations\n", *fixedIterations) } } @@ -96,8 +97,8 @@ func init() { utils.CheckConfigError(botConfig, e, *botConfigPath) e = botConfig.Init() if e != nil { - logger.Info("") - logger.Fatal(e) + l.Info("") + logger.Fatal(l, e) } if *logPrefix != "" { @@ -105,11 +106,11 @@ func init() { fileName := fmt.Sprintf("%s_%s_%s_%s_%s_%s.log", *logPrefix, botConfig.AssetCodeA, botConfig.IssuerA, botConfig.AssetCodeB, botConfig.IssuerB, t) e = setLogFile(fileName) if e != nil { - logger.Info("") - logger.Fatal(e) + l.Info("") + logger.Fatal(l, e) return } - logger.Infof("logging to file: %s", fileName) + l.Infof("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() @@ -119,14 +120,14 @@ func init() { if *simMode { startupMessage += " (simulation mode)" } - logger.Info(startupMessage) + l.Info(startupMessage) // now that we've got the basic messages logged, validate the cli params validateCliParams() // only log botConfig file here so it can be included in the log file utils.LogConfig(botConfig) - logger.Infof("Trading %s:%s for %s:%s\n", botConfig.AssetCodeA, botConfig.IssuerA, botConfig.AssetCodeB, botConfig.IssuerB) + l.Infof("Trading %s:%s for %s:%s\n", botConfig.AssetCodeA, botConfig.IssuerA, botConfig.AssetCodeB, botConfig.IssuerB) client := &horizon.Client{ URL: botConfig.HorizonURL, @@ -135,7 +136,7 @@ func init() { alert, e := monitoring.MakeAlert(botConfig.AlertType, botConfig.AlertAPIKey) if e != nil { - logger.Infof("Unable to set up monitoring for alert type '%s' with the given API key\n", botConfig.AlertType) + l.Infof("Unable to set up monitoring for alert type '%s' with the given API key\n", botConfig.AlertType) } // --- start initialization of objects ---- threadTracker := multithreading.MakeThreadTracker() @@ -169,8 +170,8 @@ func init() { dataKey := model.MakeSortedBotKey(assetBase, assetQuote) strat, e := plugins.MakeStrategy(sdex, tradingPair, &assetBase, &assetQuote, *strategy, *stratConfigPath, *simMode) if e != nil { - logger.Info("") - logger.Fatal(e) + l.Info("") + logger.Fatal(l, e) // we want to delete all the offers and exit here since there is something wrong with our setup deleteAllOffersAndExit(botConfig, client, sdex) } @@ -192,17 +193,18 @@ func init() { ) // --- end initialization of objects --- - logger.Infof("validating trustlines...\n") + l.Infof("validating trustlines...\n") validateTrustlines(client, &botConfig) - logger.Infof("trustlines valid\n") + l.Infof("trustlines valid\n") // --- start initialization of services --- if botConfig.MonitoringPort != 0 { go func() { e := startMonitoringServer(botConfig) if e != nil { - logger.Info("") - logger.Infof("unable to start the monitoring server or problem encountered while running server: %s\n", e) + l.Info("") + l.Info("unable to start the monitoring server or problem encountered while running server:") + logger.Fatal(l, e) // we want to delete all the offers and exit here because we don't want the bot to run if monitoring isn't working // if monitoring is desired but not working properly, we want the bot to be shut down and guarantee that there // aren't outstanding offers. @@ -213,8 +215,8 @@ func init() { strategyFillHandlers, e := strat.GetFillHandlers() if e != nil { - log.Println() - log.Printf("problem encountered while instantiating the fill tracker: %s\n", e) + l.Info("") + l.Infof("problem encountered while instantiating the fill tracker: %s\n", e) deleteAllOffersAndExit(botConfig, client, sdex) } if botConfig.FillTrackerSleepMillis != 0 { @@ -227,25 +229,25 @@ func init() { } } - log.Printf("Starting fill tracker with %d handlers\n", fillTracker.NumHandlers()) + l.Infof("Starting fill tracker with %d handlers\n", fillTracker.NumHandlers()) go func() { e := fillTracker.TrackFills() if e != nil { - log.Println() - log.Printf("problem encountered while running the fill tracker: %s\n", e) + l.Info("") + l.Infof("problem encountered while running the fill tracker: %s\n", e) // we want to delete all the offers and exit here because we don't want the bot to run if fill tracking isn't working deleteAllOffersAndExit(botConfig, client, sdex) } }() } else if strategyFillHandlers != nil && len(strategyFillHandlers) > 0 { - log.Println() - log.Printf("error: strategy has FillHandlers but fill tracking was disabled (set FILL_TRACKER_SLEEP_MILLIS to a non-zero value)\n") + l.Info("") + l.Infof("error: strategy has FillHandlers but fill tracking was disabled (set FILL_TRACKER_SLEEP_MILLIS to a non-zero value)\n") // we want to delete all the offers and exit here because we don't want the bot to run if fill tracking isn't working deleteAllOffersAndExit(botConfig, client, sdex) } // --- end initialization of services --- - logger.Info("Starting the trader bot...") + l.Info("Starting the trader bot...") bot.Start() } } @@ -284,15 +286,14 @@ func startMonitoringServer(botConfig trader.BotConfig) error { return fmt.Errorf("unable to initialize the metrics server: %s", e) } - logger.Infof("Starting monitoring server on port %d\n", botConfig.MonitoringPort) + l.Infof("Starting monitoring server on port %d\n", botConfig.MonitoringPort) return server.StartServer(botConfig.MonitoringPort, botConfig.MonitoringTLSCert, botConfig.MonitoringTLSKey) } func validateTrustlines(client *horizon.Client, botConfig *trader.BotConfig) { account, e := client.LoadAccount(botConfig.TradingAccount()) if e != nil { - logger.Info("") - logger.Fatal(e) + logger.Fatal(l, e) } missingTrustlines := []string{} @@ -311,49 +312,48 @@ func validateTrustlines(client *horizon.Client, botConfig *trader.BotConfig) { } if len(missingTrustlines) > 0 { - logger.Info("") - logger.Fatalf("error: your trading account does not have the required trustlines: %v\n", missingTrustlines) + e := fmt.Errorf("error: your trading account does not have the required trustlines: %v", missingTrustlines) + logger.Fatal(l, e) } } func deleteAllOffersAndExit(botConfig trader.BotConfig, client *horizon.Client, sdex *plugins.SDEX) { - logger.Info("") - logger.Infof("deleting all offers and then exiting...\n") + l.Info("") + l.Infof("deleting all offers and then exiting...\n") offers, e := utils.LoadAllOffers(botConfig.TradingAccount(), client) if e != nil { - logger.Info("") - logger.Fatal(e) + logger.Fatal(l, e) return } sellingAOffers, buyingAOffers := utils.FilterOffers(offers, botConfig.AssetBase(), botConfig.AssetQuote()) allOffers := append(sellingAOffers, buyingAOffers...) dOps := sdex.DeleteAllOffers(allOffers) - logger.Infof("created %d operations to delete offers\n", len(dOps)) + l.Infof("created %d operations to delete offers\n", len(dOps)) if len(dOps) > 0 { e := sdex.SubmitOps(dOps, func(hash string, e error) { if e != nil { - logger.Info("") - logger.Fatal(e) + logger.Fatal(l, e) return } - logger.Fatalf("...deleted all offers, exiting") + e = fmt.Errorf("...deleted all offers, exiting") + logger.Fatal(l, e) }) if e != nil { - logger.Info("") - logger.Fatal(e) + logger.Fatal(l, e) return } for { sleepSeconds := 10 - logger.Infof("sleeping for %d seconds until our deletion is confirmed and we exit...\n", sleepSeconds) + l.Infof("sleeping for %d seconds until our deletion is confirmed and we exit...\n", sleepSeconds) time.Sleep(time.Duration(sleepSeconds) * time.Second) } } else { - logger.Fatalf("...nothing to delete, exiting") + e := fmt.Errorf("...nothing to delete, exiting") + logger.Fatal(l, e) } } diff --git a/support/logger/basicLogger.go b/support/logger/basicLogger.go new file mode 100644 index 000000000..943ccbc1a --- /dev/null +++ b/support/logger/basicLogger.go @@ -0,0 +1,36 @@ +package logger + +import "log" + +// BasicLogger is a standard logger +type BasicLogger struct { +} + +// Info impl +func (l *BasicLogger) Info(msg string) { + log.Println(msg) +} + +// Infof impl +func (l *BasicLogger) Infof(msg string, args ...interface{}) { + log.Printf(msg, args...) +} + +// Error impl +func (l *BasicLogger) Error(msg string) { + log.Print(msg) +} + +// Efforf impl +func (l *BasicLogger) Errorf(msg string, args ...interface{}) { + log.Printf(msg) +} + +// ensure it implements Logger +var _ Logger = &BasicLogger{} + +// MakeBasicLogger is the factory method +func MakeBasicLogger() Logger { + var l *BasicLogger + return l +} diff --git a/support/logger/logger.go b/support/logger/logger.go new file mode 100644 index 000000000..6be765ecc --- /dev/null +++ b/support/logger/logger.go @@ -0,0 +1,25 @@ +package logger + +import "os" + +// Logger is the base logger interface +type Logger interface { + // basic messages, appends a newline (\n) after each entry + Info(msg string) + + // basic messages, can be custom formatted, similar to fmt.Printf. User needs to add a \n if they want a newline after the log entry + Infof(msg string, args ...interface{}) + + // error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. Appends a newline (\n) after each entry. + Error(msg string) + + // error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. User needs to add a \n if they want a newline after the log entry. + Errorf(msg string, args ...interface{}) +} + +// Fatal is a convenience method that can be used with any Logger to log a fatal error +func Fatal(l Logger, e error) { + l.Info("") + l.Errorf("%s", e) + os.Exit(1) +} diff --git a/support/loggers/loggers.go b/support/loggers/loggers.go deleted file mode 100644 index de0100c60..000000000 --- a/support/loggers/loggers.go +++ /dev/null @@ -1,53 +0,0 @@ -package loggers // I didn't call the packacke "logging" because the go-loggeing framework's package is "logging" so we'll need to be different when we switch - -import ( - "log" -) - -type Logger interface { - // basic messages, appends a newline (\n) after each entry - Info(msg string) - - // basic messages, can be custom formatted, similar to fmt.Printf. User needs to add a \n if they want a newline after the log entry - Infof(msg string, args ...interface{}) - - // error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. Appends a newline (\n) after each entry. - Error(msg string) - - // error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. User needs to add a \n if they want a newline after the log entry. - Errorf(msg string, args ...interface{}) - - // added Fatal and Fatalf because trade.go (and elsewhere) use log.Fatal - // fatal error messages, with newline - Fatal(e error) - - // formatted fatal error messages, without automatic newline - Fatalf(e error, args ...interface{}) -} - -type basicLogger struct { -} - -func (l basicLogger) Info(msg string) { - log.Println(msg) -} - -func (l basicLogger) Infof(msg string, args ...interface{}) { - log.Printf(msg, args...) -} - -func (l basicLogger) Error(msg string) { - log.Println(msg) // isn't actually differnt from Info until we do structured logs -} - -func (l basicLogger) Errorf(msg string, args ...interface{}) { - log.Printf(msg, args...) // isn't actually differnt from Infof until we do structured logs -} - -func (l basicLogger) Fatal(e error) { - log.Fatal(e) -} - -func (l basicLogger) Fatalf(e string, args ...interface{}) { - log.Fatalf(e, args...) -} From 243808560a918b1f5641a9d0eb7c09d86ba29fea Mon Sep 17 00:00:00 2001 From: Reidmcc Date: Thu, 10 Jan 2019 16:35:51 -0600 Subject: [PATCH 5/7] remove loggers.go --- support/loggers/loggers.go | 53 -------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 support/loggers/loggers.go diff --git a/support/loggers/loggers.go b/support/loggers/loggers.go deleted file mode 100644 index fa748bd58..000000000 --- a/support/loggers/loggers.go +++ /dev/null @@ -1,53 +0,0 @@ -package loggers // I didn't call the packacke "logging" because the go-loggeing framework's package is "logging" so we'll need to be different when we switch - -import ( - "log" -) - -type Logger interface { - // basic messages, appends a newline (\n) after each entry - Info(msg string) - - // basic messages, can be custom formatted, similar to fmt.Printf. User needs to add a \n if they want a newline after the log entry - Infof(msg string, args ...interface{}) - - // error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. Appends a newline (\n) after each entry. - Error(msg string) - - // error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. User needs to add a \n if they want a newline after the log entry. - Errorf(msg string, args ...interface{}) - - // added Fatal and Fatalf because trade.go (and elsewhere) use log.Fatal - // fatal error messages, with newline - Fatal(e error) - - // formatted fatal error messages, without automatic newline - Fatalf(e error, args ...interface{}) -} - -type BasicLogger struct { -} - -func (l BasicLogger) Info(msg string) { - log.Println(msg) -} - -func (l BasicLogger) Infof(msg string, args ...interface{}) { - log.Printf(msg, args...) -} - -func (l BasicLogger) Error(msg string) { - log.Println(msg) // isn't actually differnt from Info until we do structured logs -} - -func (l BasicLogger) Errorf(msg string, args ...interface{}) { - log.Printf(msg, args...) // isn't actually differnt from Infof until we do structured logs -} - -func (l BasicLogger) Fatal(e error) { - log.Fatal(e) -} - -func (l BasicLogger) Fatalf(e string, args ...interface{}) { - log.Fatalf(e, args...) -} From 5b199526cf25f65e2d7e490dec2e7913e79026f6 Mon Sep 17 00:00:00 2001 From: Reidmcc Date: Fri, 11 Jan 2019 19:15:58 -0600 Subject: [PATCH 6/7] remove gloval var, format edits --- cmd/trade.go | 55 +++++++++++++++++------------------ support/logger/basicLogger.go | 19 ++++++------ 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/cmd/trade.go b/cmd/trade.go index 2720a2bc8..625eda7ec 100644 --- a/cmd/trade.go +++ b/cmd/trade.go @@ -32,8 +32,6 @@ var tradeCmd = &cobra.Command{ Example: tradeExamples, } -var l *logger.BasicLogger - func requiredFlag(flag string) { e := tradeCmd.MarkFlagRequired(flag) if e != nil { @@ -48,11 +46,10 @@ func hiddenFlag(flag string) { } } -func logPanic() { +func logPanic(l logger.Logger) { if r := recover(); r != nil { st := debug.Stack() l.Errorf("PANIC!! recovered to log it in the file\npanic: %v\n\n%s\n", r, string(st)) - os.Exit(1) } } @@ -74,7 +71,7 @@ func init() { hiddenFlag("operationalBufferNonNativePct") tradeCmd.Flags().SortFlags = false - validateCliParams := func() { + validateCliParams := func(l logger.Logger) { if *operationalBuffer < 0 { panic(fmt.Sprintf("invalid operationalBuffer argument, must be non-negative: %f", *operationalBuffer)) } @@ -92,12 +89,12 @@ func init() { } tradeCmd.Run = func(ccmd *cobra.Command, args []string) { + l := logger.MakeBasicLogger() var botConfig trader.BotConfig e := config.Read(*botConfigPath, &botConfig) utils.CheckConfigError(botConfig, e, *botConfigPath) e = botConfig.Init() if e != nil { - l.Info("") logger.Fatal(l, e) } @@ -110,10 +107,10 @@ func init() { logger.Fatal(l, e) return } - l.Infof("logging to file: %s", fileName) + l.Infof("logging to file: %s\n", fileName) // we want to create a deferred recovery function here that will log panics to the log file and then exit - defer logPanic() + defer logPanic(l) } startupMessage := "Starting Kelp Trader: " + version + " [" + gitHash + "]" @@ -123,7 +120,7 @@ func init() { l.Info(startupMessage) // now that we've got the basic messages logged, validate the cli params - validateCliParams() + validateCliParams(l) // only log botConfig file here so it can be included in the log file utils.LogConfig(botConfig) @@ -173,7 +170,7 @@ func init() { l.Info("") logger.Fatal(l, e) // we want to delete all the offers and exit here since there is something wrong with our setup - deleteAllOffersAndExit(botConfig, client, sdex) + deleteAllOffersAndExit(l, botConfig, client, sdex) } timeController := plugins.MakeIntervalTimeController(time.Duration(botConfig.TickIntervalSeconds) * time.Second) @@ -193,14 +190,14 @@ func init() { ) // --- end initialization of objects --- - l.Infof("validating trustlines...\n") - validateTrustlines(client, &botConfig) - l.Infof("trustlines valid\n") + l.Info("validating trustlines...") + validateTrustlines(l, client, &botConfig) + l.Info("trustlines valid") // --- start initialization of services --- if botConfig.MonitoringPort != 0 { go func() { - e := startMonitoringServer(botConfig) + e := startMonitoringServer(l, botConfig) if e != nil { l.Info("") l.Info("unable to start the monitoring server or problem encountered while running server:") @@ -208,7 +205,7 @@ func init() { // we want to delete all the offers and exit here because we don't want the bot to run if monitoring isn't working // if monitoring is desired but not working properly, we want the bot to be shut down and guarantee that there // aren't outstanding offers. - deleteAllOffersAndExit(botConfig, client, sdex) + deleteAllOffersAndExit(l, botConfig, client, sdex) } }() } @@ -216,8 +213,9 @@ func init() { strategyFillHandlers, e := strat.GetFillHandlers() if e != nil { l.Info("") - l.Infof("problem encountered while instantiating the fill tracker: %s\n", e) - deleteAllOffersAndExit(botConfig, client, sdex) + l.Info("problem encountered while instantiating the fill tracker:") + logger.Fatal(l, e) + deleteAllOffersAndExit(l, botConfig, client, sdex) } if botConfig.FillTrackerSleepMillis != 0 { fillTracker := plugins.MakeFillTracker(tradingPair, threadTracker, sdex, botConfig.FillTrackerSleepMillis) @@ -234,16 +232,17 @@ func init() { e := fillTracker.TrackFills() if e != nil { l.Info("") - l.Infof("problem encountered while running the fill tracker: %s\n", e) + l.Info("problem encountered while running the fill tracker:") + logger.Fatal(l, e) // we want to delete all the offers and exit here because we don't want the bot to run if fill tracking isn't working - deleteAllOffersAndExit(botConfig, client, sdex) + deleteAllOffersAndExit(l, botConfig, client, sdex) } }() } else if strategyFillHandlers != nil && len(strategyFillHandlers) > 0 { l.Info("") - l.Infof("error: strategy has FillHandlers but fill tracking was disabled (set FILL_TRACKER_SLEEP_MILLIS to a non-zero value)\n") + l.Info("error: strategy has FillHandlers but fill tracking was disabled (set FILL_TRACKER_SLEEP_MILLIS to a non-zero value)") // we want to delete all the offers and exit here because we don't want the bot to run if fill tracking isn't working - deleteAllOffersAndExit(botConfig, client, sdex) + deleteAllOffersAndExit(l, botConfig, client, sdex) } // --- end initialization of services --- @@ -252,7 +251,7 @@ func init() { } } -func startMonitoringServer(botConfig trader.BotConfig) error { +func startMonitoringServer(l logger.Logger, botConfig trader.BotConfig) error { serverConfig := &networking.Config{ GoogleClientID: botConfig.GoogleClientID, GoogleClientSecret: botConfig.GoogleClientSecret, @@ -290,7 +289,7 @@ func startMonitoringServer(botConfig trader.BotConfig) error { return server.StartServer(botConfig.MonitoringPort, botConfig.MonitoringTLSCert, botConfig.MonitoringTLSKey) } -func validateTrustlines(client *horizon.Client, botConfig *trader.BotConfig) { +func validateTrustlines(l logger.Logger, client *horizon.Client, botConfig *trader.BotConfig) { account, e := client.LoadAccount(botConfig.TradingAccount()) if e != nil { logger.Fatal(l, e) @@ -312,14 +311,13 @@ func validateTrustlines(client *horizon.Client, botConfig *trader.BotConfig) { } if len(missingTrustlines) > 0 { - e := fmt.Errorf("error: your trading account does not have the required trustlines: %v", missingTrustlines) - logger.Fatal(l, e) + logger.Fatal(l, fmt.Errorf("error: your trading account does not have the required trustlines: %v", missingTrustlines)) } } -func deleteAllOffersAndExit(botConfig trader.BotConfig, client *horizon.Client, sdex *plugins.SDEX) { +func deleteAllOffersAndExit(l logger.Logger, botConfig trader.BotConfig, client *horizon.Client, sdex *plugins.SDEX) { l.Info("") - l.Infof("deleting all offers and then exiting...\n") + l.Info("deleting all offers and then exiting...") offers, e := utils.LoadAllOffers(botConfig.TradingAccount(), client) if e != nil { @@ -352,8 +350,7 @@ func deleteAllOffersAndExit(botConfig trader.BotConfig, client *horizon.Client, time.Sleep(time.Duration(sleepSeconds) * time.Second) } } else { - e := fmt.Errorf("...nothing to delete, exiting") - logger.Fatal(l, e) + logger.Fatal(l, fmt.Errorf("...nothing to delete, exiting")) } } diff --git a/support/logger/basicLogger.go b/support/logger/basicLogger.go index 943ccbc1a..289a5878a 100644 --- a/support/logger/basicLogger.go +++ b/support/logger/basicLogger.go @@ -2,35 +2,34 @@ package logger import "log" -// BasicLogger is a standard logger -type BasicLogger struct { +// basicLogger is a standard logger +type basicLogger struct { } // Info impl -func (l *BasicLogger) Info(msg string) { +func (l *basicLogger) Info(msg string) { log.Println(msg) } // Infof impl -func (l *BasicLogger) Infof(msg string, args ...interface{}) { +func (l *basicLogger) Infof(msg string, args ...interface{}) { log.Printf(msg, args...) } // Error impl -func (l *BasicLogger) Error(msg string) { +func (l *basicLogger) Error(msg string) { log.Print(msg) } // Efforf impl -func (l *BasicLogger) Errorf(msg string, args ...interface{}) { - log.Printf(msg) +func (l *basicLogger) Errorf(msg string, args ...interface{}) { + log.Printf(msg, args...) } // ensure it implements Logger -var _ Logger = &BasicLogger{} +var _ Logger = &basicLogger{} // MakeBasicLogger is the factory method func MakeBasicLogger() Logger { - var l *BasicLogger - return l + return &basicLogger{} } From b3a64690ed1b16fe4d73f44fd3ef1c7df0d62e0e Mon Sep 17 00:00:00 2001 From: Reidmcc Date: Mon, 14 Jan 2019 22:07:06 -0600 Subject: [PATCH 7/7] remove bad Fatals --- cmd/trade.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cmd/trade.go b/cmd/trade.go index 8af1935bd..67f668c37 100644 --- a/cmd/trade.go +++ b/cmd/trade.go @@ -103,7 +103,6 @@ func init() { fileName := fmt.Sprintf("%s_%s_%s_%s_%s_%s.log", *logPrefix, botConfig.AssetCodeA, botConfig.IssuerA, botConfig.AssetCodeB, botConfig.IssuerB, t) e = setLogFile(fileName) if e != nil { - l.Info("") logger.Fatal(l, e) return } @@ -168,7 +167,7 @@ func init() { strat, e := plugins.MakeStrategy(sdex, tradingPair, &assetBase, &assetQuote, *strategy, *stratConfigPath, *simMode) if e != nil { l.Info("") - logger.Fatal(l, e) + l.Errorf("%s", e) // we want to delete all the offers and exit here since there is something wrong with our setup deleteAllOffersAndExit(l, botConfig, client, sdex) } @@ -204,7 +203,7 @@ func init() { if e != nil { l.Info("") l.Info("unable to start the monitoring server or problem encountered while running server:") - logger.Fatal(l, e) + l.Errorf("%s", e) // we want to delete all the offers and exit here because we don't want the bot to run if monitoring isn't working // if monitoring is desired but not working properly, we want the bot to be shut down and guarantee that there // aren't outstanding offers. @@ -217,7 +216,7 @@ func init() { if e != nil { l.Info("") l.Info("problem encountered while instantiating the fill tracker:") - logger.Fatal(l, e) + l.Errorf("%s", e) deleteAllOffersAndExit(l, botConfig, client, sdex) } if botConfig.FillTrackerSleepMillis != 0 { @@ -236,14 +235,14 @@ func init() { if e != nil { l.Info("") l.Info("problem encountered while running the fill tracker:") - logger.Fatal(l, e) + l.Errorf("%s", e) // we want to delete all the offers and exit here because we don't want the bot to run if fill tracking isn't working deleteAllOffersAndExit(l, botConfig, client, sdex) } }() } else if strategyFillHandlers != nil && len(strategyFillHandlers) > 0 { l.Info("") - l.Info("error: strategy has FillHandlers but fill tracking was disabled (set FILL_TRACKER_SLEEP_MILLIS to a non-zero value)") + l.Error("error: strategy has FillHandlers but fill tracking was disabled (set FILL_TRACKER_SLEEP_MILLIS to a non-zero value)") // we want to delete all the offers and exit here because we don't want the bot to run if fill tracking isn't working deleteAllOffersAndExit(l, botConfig, client, sdex) } @@ -339,8 +338,7 @@ func deleteAllOffersAndExit(l logger.Logger, botConfig trader.BotConfig, client logger.Fatal(l, e) return } - e = fmt.Errorf("...deleted all offers, exiting") - logger.Fatal(l, e) + logger.Fatal(l, fmt.Errorf("...deleted all offers, exiting")) }) if e != nil { logger.Fatal(l, e)