[#1611] shard: Print shard ID in component logs
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
9f7a22e2aa
commit
11c9df6f00
4 changed files with 27 additions and 0 deletions
|
@ -91,6 +91,11 @@ func New(opts ...Option) *BlobStor {
|
|||
}
|
||||
}
|
||||
|
||||
// SetLogger sets logger. It is used after the shard ID was generated to use it in logs.
|
||||
func (b *BlobStor) SetLogger(l *zap.Logger) {
|
||||
b.log = l
|
||||
}
|
||||
|
||||
// WithShallowDepth returns option to set the
|
||||
// depth of the object file subdirectory tree.
|
||||
//
|
||||
|
|
|
@ -251,6 +251,11 @@ func bucketKeyHelper(hdr string, val string) []byte {
|
|||
}
|
||||
}
|
||||
|
||||
// SetLogger sets logger. It is used after the shard ID was generated to use it in logs.
|
||||
func (db *DB) SetLogger(l *zap.Logger) {
|
||||
db.log = l
|
||||
}
|
||||
|
||||
// WithLogger returns option to set logger of DB.
|
||||
func WithLogger(l *logger.Logger) Option {
|
||||
return func(c *cfg) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package shard
|
|||
|
||||
import (
|
||||
"github.com/mr-tron/base58"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// ID represents Shard identifier.
|
||||
|
@ -41,6 +42,16 @@ func (s *Shard) UpdateID() (err error) {
|
|||
}
|
||||
if len(id) != 0 {
|
||||
s.info.ID = NewIDFromBytes(id)
|
||||
}
|
||||
|
||||
s.log = s.log.With(zap.String("shard_id", s.info.ID.String()))
|
||||
s.metaBase.SetLogger(s.log)
|
||||
s.blobStor.SetLogger(s.log)
|
||||
if s.hasWriteCache() {
|
||||
s.writeCache.SetLogger(s.log)
|
||||
}
|
||||
|
||||
if len(id) != 0 {
|
||||
return nil
|
||||
}
|
||||
return s.metaBase.WriteShardID(*s.info.ID)
|
||||
|
|
|
@ -24,6 +24,7 @@ type Cache interface {
|
|||
Iterate(IterationPrm) error
|
||||
Put(*object.Object) error
|
||||
SetMode(Mode)
|
||||
SetLogger(*zap.Logger)
|
||||
DumpInfo() Info
|
||||
|
||||
Init() error
|
||||
|
@ -111,6 +112,11 @@ func New(opts ...Option) Cache {
|
|||
return c
|
||||
}
|
||||
|
||||
// SetLogger sets logger. It is used after the shard ID was generated to use it in logs.
|
||||
func (c *cache) SetLogger(l *zap.Logger) {
|
||||
c.log = l
|
||||
}
|
||||
|
||||
func (c *cache) DumpInfo() Info {
|
||||
return Info{
|
||||
Path: c.path,
|
||||
|
|
Loading…
Reference in a new issue