mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 23:16:52 +00:00
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:
41
helpers.go
41
helpers.go
@@ -3,11 +3,7 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/currency/translation"
|
||||
@@ -15,39 +11,10 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/stats"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
"github.com/thrasher-/gocryptotrader/portfolio"
|
||||
)
|
||||
|
||||
const (
|
||||
logFile = "debug.log"
|
||||
)
|
||||
|
||||
var (
|
||||
logFileHandle *os.File
|
||||
)
|
||||
|
||||
// InitLogFile initialises the log file
|
||||
func InitLogFile(lFile string) error {
|
||||
if logFileHandle != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
logFileHandle, err = os.OpenFile(lFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
wrt := io.MultiWriter(os.Stdout, logFileHandle)
|
||||
log.SetOutput(wrt)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetLogFile returns the debug.log file
|
||||
func GetLogFile(dir string) string {
|
||||
return dir + common.GetOSPathSlash() + logFile
|
||||
}
|
||||
|
||||
// GetAllAvailablePairs returns a list of all available pairs on either enabled
|
||||
// or disabled exchanges
|
||||
func GetAllAvailablePairs(enabledExchangesOnly bool) []pair.CurrencyPair {
|
||||
@@ -369,7 +336,7 @@ func SeedExchangeAccountInfo(data []exchange.AccountInfo) {
|
||||
if total <= 0 {
|
||||
continue
|
||||
}
|
||||
log.Printf("Portfolio: Adding new exchange address: %s, %s, %f, %s\n",
|
||||
log.Debugf("Portfolio: Adding new exchange address: %s, %s, %f, %s\n",
|
||||
exchangeName, currencyName, total, portfolio.PortfolioAddressExchange)
|
||||
port.Addresses = append(
|
||||
port.Addresses,
|
||||
@@ -378,7 +345,7 @@ func SeedExchangeAccountInfo(data []exchange.AccountInfo) {
|
||||
)
|
||||
} else {
|
||||
if total <= 0 {
|
||||
log.Printf("Portfolio: Removing %s %s entry.\n", exchangeName,
|
||||
log.Debugf("Portfolio: Removing %s %s entry.\n", exchangeName,
|
||||
currencyName)
|
||||
port.RemoveExchangeAddress(exchangeName, currencyName)
|
||||
} else {
|
||||
@@ -387,7 +354,7 @@ func SeedExchangeAccountInfo(data []exchange.AccountInfo) {
|
||||
continue
|
||||
}
|
||||
if balance != total {
|
||||
log.Printf("Portfolio: Updating %s %s entry with balance %f.\n",
|
||||
log.Debugf("Portfolio: Updating %s %s entry with balance %f.\n",
|
||||
exchangeName, currencyName, total)
|
||||
port.UpdateExchangeAddressBalance(exchangeName, currencyName, total)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user