Skip to content

Commit

Permalink
Move proposal spam to trace level
Browse files Browse the repository at this point in the history
  • Loading branch information
tadaskay committed Jan 9, 2020
1 parent e4ced40 commit c3053e3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
33 changes: 33 additions & 0 deletions communication/nats/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2020 The "MysteriumNetwork/node" Authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package nats

import (
"github.com/nats-io/go-nats"
"github.com/rs/zerolog"
)

// Change this to slice as needed
var traceLevelSubject = "*.proposal-register"

func levelFor(msg *nats.Msg) zerolog.Level {
if msg.Subject == traceLevelSubject {
return zerolog.TraceLevel
}
return zerolog.DebugLevel
}
4 changes: 2 additions & 2 deletions communication/nats/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (receiver *receiverNATS) Receive(consumer communication.MessageConsumer) er
messageTopic := receiver.messageTopic + string(consumer.GetMessageEndpoint())

messageHandler := func(msg *nats.Msg) {
log.Debug().Msgf("Message %q received: %s", messageTopic, msg.Data)
log.WithLevel(levelFor(msg)).Msgf("Message %q received: %s", messageTopic, msg.Data)
messagePtr := consumer.NewMessage()
err := receiver.codec.Unpack(msg.Data, messagePtr)
if err != nil {
Expand Down Expand Up @@ -96,7 +96,7 @@ func (receiver *receiverNATS) Respond(consumer communication.RequestConsumer) er
requestTopic := receiver.messageTopic + string(consumer.GetRequestEndpoint())

messageHandler := func(msg *nats.Msg) {
log.Debug().Msgf("Request %q received: %s", requestTopic, msg.Data)
log.WithLevel(levelFor(msg)).Msgf("Request %q received: %s", requestTopic, msg.Data)
requestPtr := consumer.NewRequest()
err := receiver.codec.Unpack(msg.Data, requestPtr)
if err != nil {
Expand Down

0 comments on commit c3053e3

Please sign in to comment.