do not spam log file in case JsonRpc2 client can't read data

* only log an error message at max every 5 minutes

see #186
This commit is contained in:
Bernhard B
2021-12-05 17:48:44 +01:00
parent 7b9c5a3fcb
commit ed8916ce0e

View File

@@ -7,6 +7,7 @@ import (
uuid "github.com/gofrs/uuid" uuid "github.com/gofrs/uuid"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net" "net"
"time"
) )
type Error struct { type Error struct {
@@ -30,6 +31,7 @@ type JsonRpc2Client struct {
conn net.Conn conn net.Conn
receivedMessageResponses chan JsonRpc2MessageResponse receivedMessageResponses chan JsonRpc2MessageResponse
receivedMessages chan JsonRpc2ReceivedMessage receivedMessages chan JsonRpc2ReceivedMessage
lastTimeErrorMessageSent time.Time
} }
func NewJsonRpc2Client() *JsonRpc2Client { func NewJsonRpc2Client() *JsonRpc2Client {
@@ -98,7 +100,11 @@ func (r *JsonRpc2Client) ReceiveData(number string) {
for { for {
str, err := connbuf.ReadString('\n') str, err := connbuf.ReadString('\n')
if err != nil { if err != nil {
log.Error("Couldn't read data for number ", number, ": ", err.Error(), ". Is the number properly registered?") elapsed := time.Since(r.lastTimeErrorMessageSent)
if(elapsed) > time.Duration(5*time.Minute) { //avoid spamming the log file and only log the message at max every 5 minutes
log.Error("Couldn't read data for number ", number, ": ", err.Error(), ". Is the number properly registered?")
r.lastTimeErrorMessageSent = time.Now()
}
continue continue
} }
//log.Info("Received data = ", str) //log.Info("Received data = ", str)