Implement Logger (#228)

* Added new base logger

* updated example and test configs

* updated exchange helpers restful router & server

* logPath is now passed to the logger to remove dependency on common package

* updated everything besides exchanges to use new logger

* alphapoint to bitmex done

* updated bitmex bitstamp bittrex btcc and also performance changes to logger

* btcmarkets coinbase coinut exmo gateio wrappers updated

* gateio and gemini logger updated

* hitbtc huobi itbit & kraken updated

* All exchanges updatd

* return correct error for disabled websocket

* don't disconnect client on invalid json

* updated router internal logging

* log.Fatal to t.Error for tests

* Changed from fatal to error failure to set maxprocs

* output ANSI codes for everything but windows for now due to lack of windows support

* added error handling to logger and unit tests

* clear wording on print -> log.print

* added benchmark test

* cleaned up import sections

* Updated logger based on PR requests (added default config options on failure/setting errors)

* ah this should fix travici enc config issue

* Load entire config and clear out logging to hopefully fix travisci issue

* wording & test error handling

* fixed formatting issues based on feedback

* fixed formatting issues based on feedback

* changed CheckDir to use mkdirall instead of mkdir and other changes based on feedback
This commit is contained in:
Andrew
2019-01-08 21:56:22 +11:00
committed by Adrian Gallagher
parent bfbd496c3a
commit d01e7bad72
103 changed files with 1028 additions and 657 deletions

View File

@@ -2,7 +2,6 @@ package main
import (
"encoding/json"
"log"
"net/http"
"github.com/gorilla/mux"
@@ -10,6 +9,7 @@ import (
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
log "github.com/thrasher-/gocryptotrader/logger"
)
// AllEnabledExchangeOrderbooks holds the enabled exchange orderbooks
@@ -50,7 +50,7 @@ func RESTfulJSONResponse(w http.ResponseWriter, r *http.Request, response interf
// RESTfulError prints the REST method and error
func RESTfulError(method string, err error) {
log.Printf("RESTful %s: server failed to send JSON response. Error %s",
log.Errorf("RESTful %s: server failed to send JSON response. Error %s",
method, err)
}
@@ -101,7 +101,7 @@ func RESTGetOrderbook(w http.ResponseWriter, r *http.Request) {
response, err := GetSpecificOrderbook(currency, exchange, assetType)
if err != nil {
log.Printf("Failed to fetch orderbook for %s currency: %s\n", exchange,
log.Errorf("Failed to fetch orderbook for %s currency: %s\n", exchange,
currency)
return
}
@@ -124,7 +124,7 @@ func GetAllActiveOrderbooks() []EnabledExchangeOrderbooks {
currencies := individualBot.GetEnabledCurrencies()
assetTypes, err := exchange.GetExchangeAssetTypes(exchangeName)
if err != nil {
log.Printf("failed to get %s exchange asset types. Error: %s",
log.Errorf("failed to get %s exchange asset types. Error: %s",
exchangeName, err)
continue
}
@@ -143,7 +143,7 @@ func GetAllActiveOrderbooks() []EnabledExchangeOrderbooks {
}
if err != nil {
log.Printf("failed to get %s %s orderbook. Error: %s",
log.Errorf("failed to get %s %s orderbook. Error: %s",
currency.Pair().String(),
exchangeName,
err)
@@ -193,7 +193,7 @@ func RESTGetTicker(w http.ResponseWriter, r *http.Request) {
}
response, err := GetSpecificTicker(currency, exchange, assetType)
if err != nil {
log.Printf("Failed to fetch ticker for %s currency: %s\n", exchange,
log.Errorf("Failed to fetch ticker for %s currency: %s\n", exchange,
currency)
return
}
@@ -217,7 +217,7 @@ func GetAllActiveTickers() []EnabledExchangeCurrencies {
currency := x
assetTypes, err := exchange.GetExchangeAssetTypes(exchangeName)
if err != nil {
log.Printf("failed to get %s exchange asset types. Error: %s",
log.Errorf("failed to get %s exchange asset types. Error: %s",
exchangeName, err)
continue
}
@@ -233,7 +233,7 @@ func GetAllActiveTickers() []EnabledExchangeCurrencies {
}
if err != nil {
log.Printf("failed to get %s %s ticker. Error: %s",
log.Errorf("failed to get %s %s ticker. Error: %s",
currency.Pair().String(),
exchangeName,
err)
@@ -267,12 +267,12 @@ func GetAllEnabledExchangeAccountInfo() AllEnabledExchangeAccounts {
for _, individualBot := range bot.exchanges {
if individualBot != nil && individualBot.IsEnabled() {
if !individualBot.GetAuthenticatedAPISupport() {
log.Printf("GetAllEnabledExchangeAccountInfo: Skippping %s due to disabled authenticated API support.", individualBot.GetName())
log.Warnf("GetAllEnabledExchangeAccountInfo: Skippping %s due to disabled authenticated API support.", individualBot.GetName())
continue
}
individualExchange, err := individualBot.GetAccountInfo()
if err != nil {
log.Printf("Error encountered retrieving exchange account info for %s. Error %s",
log.Errorf("Error encountered retrieving exchange account info for %s. Error %s",
individualBot.GetName(), err)
continue
}