mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 07:26:47 +00:00
New logging system (#319)
* First pass at adding new logging system * NewLogger * NewLogger * WIP * silly bug fix * :D removed files * removed old logging interface * added tests * added tests * Started to add new lines to all f calls * Added subsystem log types * Logger improvements * Further performance improvements * changes to logger and sublogger creation * Renamed Logging types * removed old print statement * changes based on feedback * moved sublogger types to own file * :) * added console as output type * added get level command * added get/set log level via grpc command * added check for output being empty for migration support * first pass at log rotation * added log rotation * :D derp fixed * added tests * changes based on feedback * changed log type * comments * renamed file -> fileSettings * typo fix * changes based on feedback * gofmt ran on additional files * gofmt ran on additional files
This commit is contained in:
@@ -119,17 +119,17 @@ func (w *Websocket) wsConnectionMonitor() {
|
||||
w.DataHandler <- fmt.Errorf("%v WsConnectionMonitor: websocket disabled, shutting down", w.exchangeName)
|
||||
err := w.Shutdown()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.WebsocketMgr, err)
|
||||
}
|
||||
if w.verbose {
|
||||
log.Debugf("%v WsConnectionMonitor exiting", w.exchangeName)
|
||||
log.Debugf(log.WebsocketMgr, "%v WsConnectionMonitor exiting", w.exchangeName)
|
||||
}
|
||||
return
|
||||
}
|
||||
w.m.Unlock()
|
||||
err := w.checkConnection()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error(log.WebsocketMgr, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,18 +138,18 @@ func (w *Websocket) wsConnectionMonitor() {
|
||||
// Will reconnect on disconnect
|
||||
func (w *Websocket) checkConnection() error {
|
||||
if w.verbose {
|
||||
log.Debugf("%v checking connection", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v checking connection", w.exchangeName)
|
||||
}
|
||||
switch {
|
||||
case !w.IsConnected() && !w.IsConnecting():
|
||||
w.m.Lock()
|
||||
defer w.m.Unlock()
|
||||
if w.verbose {
|
||||
log.Debugf("%v no connection. Attempt %v/%v", w.exchangeName, w.noConnectionChecks, w.noConnectionCheckLimit)
|
||||
log.Debugf(log.ExchangeSys, "%v no connection. Attempt %v/%v", w.exchangeName, w.noConnectionChecks, w.noConnectionCheckLimit)
|
||||
}
|
||||
if w.noConnectionChecks >= w.noConnectionCheckLimit {
|
||||
if w.verbose {
|
||||
log.Debugf("%v resetting connection", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v resetting connection", w.exchangeName)
|
||||
}
|
||||
w.connecting = true
|
||||
go w.WebsocketReset()
|
||||
@@ -163,7 +163,7 @@ func (w *Websocket) checkConnection() error {
|
||||
w.reconnectionLimit*int(connectionMonitorDelay.Seconds()))
|
||||
}
|
||||
if w.verbose {
|
||||
log.Debugf("%v Busy reconnecting", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v Busy reconnecting", w.exchangeName)
|
||||
}
|
||||
w.reconnectionChecks++
|
||||
default:
|
||||
@@ -200,7 +200,7 @@ func (w *Websocket) Shutdown() error {
|
||||
}
|
||||
|
||||
if w.verbose {
|
||||
log.Debugf("%v shutting down websocket channels", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v shutting down websocket channels", w.exchangeName)
|
||||
}
|
||||
timer := time.NewTimer(15 * time.Second)
|
||||
c := make(chan struct{}, 1)
|
||||
@@ -209,7 +209,7 @@ func (w *Websocket) Shutdown() error {
|
||||
close(w.ShutdownC)
|
||||
w.Wg.Wait()
|
||||
if w.verbose {
|
||||
log.Debugf("%v completed websocket channel shutdown", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v completed websocket channel shutdown", w.exchangeName)
|
||||
}
|
||||
c <- struct{}{}
|
||||
}(c)
|
||||
@@ -229,15 +229,15 @@ func (w *Websocket) WebsocketReset() error {
|
||||
err := w.Shutdown()
|
||||
if err != nil {
|
||||
// does not return here to allow connection to be made if already shut down
|
||||
log.Errorf("%v shutdown error: %v", w.exchangeName, err)
|
||||
log.Errorf(log.ExchangeSys, "%v shutdown error: %v", w.exchangeName, err)
|
||||
}
|
||||
log.Infof("%v reconnecting to websocket", w.exchangeName)
|
||||
log.Infof(log.WebsocketMgr, "%v reconnecting to websocket", w.exchangeName)
|
||||
w.m.Lock()
|
||||
w.init = true
|
||||
w.m.Unlock()
|
||||
err = w.Connect()
|
||||
if err != nil {
|
||||
log.Errorf("%v connection error: %v", w.exchangeName, err)
|
||||
log.Errorf(log.ExchangeSys, "%v connection error: %v", w.exchangeName, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -260,7 +260,7 @@ func (w *Websocket) trafficMonitor(wg *sync.WaitGroup) {
|
||||
select {
|
||||
case <-w.ShutdownC: // Returns on shutdown channel close
|
||||
if w.verbose {
|
||||
log.Debugf("%v trafficMonitor shutdown message received", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v trafficMonitor shutdown message received", w.exchangeName)
|
||||
}
|
||||
return
|
||||
case <-w.TrafficAlert: // Resets timer on traffic
|
||||
@@ -271,13 +271,13 @@ func (w *Websocket) trafficMonitor(wg *sync.WaitGroup) {
|
||||
}
|
||||
w.m.Unlock()
|
||||
if w.verbose {
|
||||
log.Debugf("%v received a traffic alert", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v received a traffic alert", w.exchangeName)
|
||||
}
|
||||
trafficTimer.Reset(WebsocketTrafficLimitTime)
|
||||
case <-trafficTimer.C: // Falls through when timer runs out
|
||||
newtimer := time.NewTimer(10 * time.Second) // New secondary timer set
|
||||
if w.verbose {
|
||||
log.Debugf("%v has not received a traffic alert in 5 seconds.", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v has not received a traffic alert in 5 seconds.", w.exchangeName)
|
||||
}
|
||||
w.m.Lock()
|
||||
if w.connected {
|
||||
@@ -296,7 +296,7 @@ func (w *Websocket) trafficMonitor(wg *sync.WaitGroup) {
|
||||
|
||||
case <-newtimer.C: // If secondary timer runs state timeout is sent to the data handler
|
||||
if w.verbose {
|
||||
log.Debugf("%v has not received a traffic alert in 15 seconds, exiting", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v has not received a traffic alert in 15 seconds, exiting", w.exchangeName)
|
||||
}
|
||||
w.DataHandler <- fmt.Errorf("trafficMonitor %v", WebsocketStateTimeout)
|
||||
return
|
||||
@@ -308,7 +308,7 @@ func (w *Websocket) trafficMonitor(wg *sync.WaitGroup) {
|
||||
// If not connected dive rt traffic from REST to websocket
|
||||
w.Connected <- struct{}{}
|
||||
if w.verbose {
|
||||
log.Debugf("%v has received a traffic alert. Setting status to connected", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v has received a traffic alert. Setting status to connected", w.exchangeName)
|
||||
}
|
||||
w.connected = true
|
||||
}
|
||||
@@ -722,7 +722,7 @@ func (w *Websocket) manageSubscriptions() error {
|
||||
w.Wg.Add(1)
|
||||
defer func() {
|
||||
if w.verbose {
|
||||
log.Debugf("%v ManageSubscriptions exiting", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v ManageSubscriptions exiting", w.exchangeName)
|
||||
}
|
||||
w.Wg.Done()
|
||||
}()
|
||||
@@ -731,13 +731,13 @@ func (w *Websocket) manageSubscriptions() error {
|
||||
case <-w.ShutdownC:
|
||||
w.subscribedChannels = []WebsocketChannelSubscription{}
|
||||
if w.verbose {
|
||||
log.Debugf("%v shutdown manageSubscriptions", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v shutdown manageSubscriptions", w.exchangeName)
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
time.Sleep(manageSubscriptionsDelay)
|
||||
if w.verbose {
|
||||
log.Debugf("%v checking subscriptions", w.exchangeName)
|
||||
log.Debugf(log.ExchangeSys, "%v checking subscriptions", w.exchangeName)
|
||||
}
|
||||
// Subscribe to channels Pending a subscription
|
||||
if w.SupportsFunctionality(WebsocketSubscribeSupported) {
|
||||
@@ -771,7 +771,7 @@ func (w *Websocket) subscribeToChannels() error {
|
||||
}
|
||||
if !channelIsSubscribed {
|
||||
if w.verbose {
|
||||
log.Debugf("%v Subscribing to %v %v", w.exchangeName, w.channelsToSubscribe[i].Channel, w.channelsToSubscribe[i].Currency.String())
|
||||
log.Debugf(log.ExchangeSys, "%v Subscribing to %v %v", w.exchangeName, w.channelsToSubscribe[i].Channel, w.channelsToSubscribe[i].Currency.String())
|
||||
}
|
||||
err := w.channelSubscriber(w.channelsToSubscribe[i])
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user