mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-20 08:04:28 +01:00
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:
@@ -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 {
|
||||||
|
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?")
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user