mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 07:26:47 +00:00
log: Add structured logging (#1171)
* basic implementation * log: deprecate duplicate function, add tests and refine calls. * linter: fixes * linter: update struct * linter and new type * log tests: update to not lint issue * linter: stop complaining please * glorious: nits * log: rm comment code * glorious: nits * glorious: nits * glorious: nits * glorious: nits missed --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
@@ -21,7 +21,7 @@ func (a *Alphapoint) WebsocketClient() {
|
||||
var httpResp *http.Response
|
||||
endpoint, err := a.API.Endpoints.GetURL(exchange.WebsocketSpot)
|
||||
if err != nil {
|
||||
log.Error(log.WebsocketMgr, err)
|
||||
log.Errorln(log.WebsocketMgr, err)
|
||||
}
|
||||
a.WebsocketConn, httpResp, err = dialer.Dial(endpoint, http.Header{})
|
||||
httpResp.Body.Close() // not used, so safely free the body
|
||||
@@ -38,14 +38,14 @@ func (a *Alphapoint) WebsocketClient() {
|
||||
err = a.WebsocketConn.WriteMessage(websocket.TextMessage, []byte(`{"messageType": "logon"}`))
|
||||
|
||||
if err != nil {
|
||||
log.Error(log.ExchangeSys, err)
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
return
|
||||
}
|
||||
|
||||
for a.Enabled {
|
||||
msgType, resp, err := a.WebsocketConn.ReadMessage()
|
||||
if err != nil {
|
||||
log.Error(log.ExchangeSys, err)
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (a *Alphapoint) WebsocketClient() {
|
||||
msgType := MsgType{}
|
||||
err := json.Unmarshal(resp, &msgType)
|
||||
if err != nil {
|
||||
log.Error(log.ExchangeSys, err)
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func (a *Alphapoint) WebsocketClient() {
|
||||
ticker := WebsocketTicker{}
|
||||
err = json.Unmarshal(resp, &ticker)
|
||||
if err != nil {
|
||||
log.Error(log.ExchangeSys, err)
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ func (b *Binance) batchAggregateTrades(ctx context.Context, arg *AggregatedTrade
|
||||
err := b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
if err != nil {
|
||||
log.Warn(log.ExchangeSys, err.Error())
|
||||
log.Warnln(log.ExchangeSys, err.Error())
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ func (bi *Binanceus) batchAggregateTrades(ctx context.Context, arg *AggregatedTr
|
||||
err := bi.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
if err != nil {
|
||||
log.Warn(log.ExchangeSys, err.Error())
|
||||
log.Warnln(log.ExchangeSys, err.Error())
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ func (b *Bitmex) Run(ctx context.Context) {
|
||||
if b.Verbose {
|
||||
wsEndpoint, err := b.API.Endpoints.GetURL(exchange.WebsocketSpot)
|
||||
if err != nil {
|
||||
log.Error(log.ExchangeSys, err)
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s. (url: %s).\n",
|
||||
|
||||
@@ -60,7 +60,7 @@ func (c *COINUT) WsConnect() error {
|
||||
err = c.wsAuthenticate(context.TODO())
|
||||
if err != nil {
|
||||
c.Websocket.SetCanUseAuthenticatedEndpoints(false)
|
||||
log.Error(log.WebsocketMgr, err)
|
||||
log.Errorln(log.WebsocketMgr, err)
|
||||
}
|
||||
|
||||
// define bi-directional communication
|
||||
|
||||
@@ -150,7 +150,7 @@ func (g *Gemini) Setup(exch *config.Exchange) error {
|
||||
if exch.UseSandbox {
|
||||
err = g.API.Endpoints.SetRunning(exchange.RestSpot.String(), geminiSandboxAPIURL)
|
||||
if err != nil {
|
||||
log.Error(log.ExchangeSys, err)
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ func (h *HUOBI) wsHandleData(respRaw []byte) error {
|
||||
}
|
||||
err := h.Websocket.AuthConn.SendJSONMessage(authPing)
|
||||
if err != nil {
|
||||
log.Error(log.ExchangeSys, err)
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -446,7 +446,7 @@ func (h *HUOBI) wsHandleData(respRaw []byte) error {
|
||||
func (h *HUOBI) sendPingResponse(pong int64) {
|
||||
err := h.Websocket.Conn.SendJSONMessage(WsPong{Pong: pong})
|
||||
if err != nil {
|
||||
log.Error(log.ExchangeSys, err)
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ func (o *OKCoin) WsHandleData(respRaw []byte) error {
|
||||
}
|
||||
}
|
||||
if o.Verbose {
|
||||
log.Debug(log.ExchangeSys,
|
||||
log.Debugln(log.ExchangeSys,
|
||||
o.Name+" - "+eventResponse.Event+" on channel: "+eventResponse.Channel)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ func (w *Websocket) connectionMonitor() error {
|
||||
if w.IsConnected() {
|
||||
err := w.Shutdown()
|
||||
if err != nil {
|
||||
log.Error(log.WebsocketMgr, err)
|
||||
log.Errorln(log.WebsocketMgr, err)
|
||||
}
|
||||
}
|
||||
if w.verbose {
|
||||
@@ -402,7 +402,7 @@ func (w *Websocket) connectionMonitor() error {
|
||||
if !w.IsConnecting() && !w.IsConnected() {
|
||||
err := w.Connect()
|
||||
if err != nil {
|
||||
log.Error(log.WebsocketMgr, err)
|
||||
log.Errorln(log.WebsocketMgr, err)
|
||||
}
|
||||
}
|
||||
if !timer.Stop() {
|
||||
|
||||
@@ -114,7 +114,7 @@ func AddTradesToBuffer(exchangeName string, data ...Data) error {
|
||||
func (p *Processor) Run(wg *sync.WaitGroup) {
|
||||
wg.Done()
|
||||
if !atomic.CompareAndSwapInt32(&p.started, 0, 1) {
|
||||
log.Error(log.Trade, "trade processor already started")
|
||||
log.Errorln(log.Trade, "trade processor already started")
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
@@ -136,7 +136,7 @@ func (p *Processor) Run(wg *sync.WaitGroup) {
|
||||
}
|
||||
err := SaveTradesToDatabase(bufferCopy...)
|
||||
if err != nil {
|
||||
log.Error(log.Trade, err)
|
||||
log.Errorln(log.Trade, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user