forked from TrueCloudLab/frostfs-node
[#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:
parent
d9f1491566
commit
c4a1c70089
1 changed files with 29 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue