diff --git a/pkg/local_object_storage/blobstor/blobstor.go b/pkg/local_object_storage/blobstor/blobstor.go index 2a30279f..4dbd52f5 100644 --- a/pkg/local_object_storage/blobstor/blobstor.go +++ b/pkg/local_object_storage/blobstor/blobstor.go @@ -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. // diff --git a/pkg/local_object_storage/metabase/db.go b/pkg/local_object_storage/metabase/db.go index 7f15af2a..4e3ce1cf 100644 --- a/pkg/local_object_storage/metabase/db.go +++ b/pkg/local_object_storage/metabase/db.go @@ -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) { diff --git a/pkg/local_object_storage/shard/id.go b/pkg/local_object_storage/shard/id.go index a7fdd56a..a7218426 100644 --- a/pkg/local_object_storage/shard/id.go +++ b/pkg/local_object_storage/shard/id.go @@ -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) diff --git a/pkg/local_object_storage/writecache/writecache.go b/pkg/local_object_storage/writecache/writecache.go index 52e0f8e8..29c848bd 100644 --- a/pkg/local_object_storage/writecache/writecache.go +++ b/pkg/local_object_storage/writecache/writecache.go @@ -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,