[#428] cmd/node: Implement logging writer provider

Implement simple `WriterProvider` building a `Writer` that writes incoming
data to the log. In the future, this action will be replaced by sending the
value to the manager nodes.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-03-23 21:51:31 +03:00 committed by Leonard Lyubich
parent d9f1491566
commit c4a1c70089

View file

@ -2,6 +2,7 @@ package main
import (
"bytes"
"encoding/hex"
netmapcore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
@ -9,6 +10,7 @@ import (
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"github.com/pkg/errors"
"go.uber.org/zap"
)
type localTrustStorage struct {
@ -88,3 +90,30 @@ func (it *localTrustIterator) Iterate(h reputation.TrustHandler) error {
return nil
}
func (s *localTrustStorage) InitWriter(ctx trustcontroller.Context) (trustcontroller.Writer, error) {
return &localTrustLogger{
ctx: ctx,
log: s.log,
}, nil
}
type localTrustLogger struct {
ctx trustcontroller.Context
log *logger.Logger
}
func (l *localTrustLogger) Write(t reputation.Trust) error {
l.log.Info("new local trust",
zap.Uint64("epoch", l.ctx.Epoch()),
zap.String("peer", hex.EncodeToString(t.Peer().Bytes())),
zap.Stringer("value", t.Value()),
)
return nil
}
func (*localTrustLogger) Close() error {
return nil
}