From f037022a7a525419a523973757ba6f8a8ccb78b7 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 28 Sep 2022 10:41:01 +0300 Subject: [PATCH] [#1770] logger: Refactor `Logger` component Make it store its internal `zap.Logger`'s level. Also, make all the components to accept internal `logger.Logger` instead of `zap.Logger`; it will simplify future refactor. Signed-off-by: Pavel Karpy --- cmd/neofs-node/config.go | 2 +- cmd/neofs-node/grpc.go | 2 +- cmd/neofs-node/notificator.go | 5 +++-- cmd/neofs-node/reputation.go | 4 ++-- .../reputation/intermediate/contract.go | 2 +- pkg/innerring/blocktimer.go | 3 ++- pkg/innerring/innerring.go | 9 +++++---- .../processors/alphabet/processor.go | 5 +++-- pkg/innerring/processors/audit/processor.go | 6 +++--- pkg/innerring/processors/balance/processor.go | 5 +++-- .../processors/container/processor.go | 5 +++-- .../processors/governance/processor.go | 6 +++--- pkg/innerring/processors/neofs/processor.go | 5 +++-- pkg/innerring/processors/netmap/processor.go | 5 +++-- .../processors/reputation/processor.go | 5 +++-- .../processors/settlement/audit/calculate.go | 8 ++++---- .../processors/settlement/audit/calculator.go | 2 +- .../processors/settlement/basic/context.go | 6 +++--- pkg/innerring/processors/settlement/calls.go | 5 +++-- pkg/innerring/processors/settlement/opts.go | 2 +- pkg/innerring/rpc.go | 5 +++-- .../blobovnicza/blobovnicza.go | 4 ++-- .../blobovniczatree/blobovnicza_test.go | 3 ++- .../blobstor/blobovniczatree/generic_test.go | 5 +++-- .../blobstor/blobovniczatree/option.go | 7 ++++--- pkg/local_object_storage/blobstor/blobstor.go | 6 +++--- .../engine/delete_test.go | 3 ++- pkg/local_object_storage/engine/engine.go | 2 +- .../engine/engine_test.go | 3 ++- pkg/local_object_storage/engine/error_test.go | 5 +++-- .../engine/evacuate_test.go | 5 +++-- pkg/local_object_storage/metabase/db.go | 4 ++-- .../shard/control_test.go | 3 ++- pkg/local_object_storage/shard/dump_test.go | 3 ++- pkg/local_object_storage/shard/gc.go | 2 +- pkg/local_object_storage/shard/id.go | 3 ++- pkg/local_object_storage/shard/lock_test.go | 3 ++- pkg/local_object_storage/shard/range_test.go | 3 ++- pkg/local_object_storage/shard/shard.go | 2 +- pkg/local_object_storage/shard/shard_test.go | 7 ++++--- .../writecache/flush_test.go | 3 ++- .../writecache/generic_test.go | 3 ++- .../writecache/options.go | 7 ++++--- .../writecache/writecache.go | 7 ++++--- pkg/morph/client/constructor.go | 6 +++--- pkg/morph/event/listener.go | 5 +++-- pkg/morph/event/utils.go | 3 ++- pkg/morph/subscriber/subscriber.go | 5 +++-- pkg/services/audit/auditor/context.go | 4 ++-- pkg/services/audit/taskmanager/manager.go | 4 ++-- .../announcement/load/controller/calls.go | 8 ++++---- .../announcement/load/controller/opts.go | 2 +- .../container/announcement/load/route/opts.go | 2 +- pkg/services/notificator/nats/options.go | 4 ++-- pkg/services/notificator/nats/service.go | 5 +++-- pkg/services/notificator/service.go | 7 ++++--- pkg/services/object/acl/v2/classifier.go | 3 ++- pkg/services/object/acl/v2/opts.go | 4 ++-- pkg/services/object/acl/v2/service.go | 5 +++-- pkg/services/object/delete/exec.go | 4 ++-- pkg/services/object/delete/service.go | 4 ++-- pkg/services/object/get/exec.go | 4 ++-- pkg/services/object/get/service.go | 4 ++-- pkg/services/object/put/service.go | 2 +- pkg/services/object/search/exec.go | 4 ++-- pkg/services/object/search/service.go | 4 ++-- .../object_manager/tombstone/checker.go | 3 ++- .../object_manager/tombstone/constructor.go | 7 ++++--- pkg/services/policer/policer.go | 4 ++-- pkg/services/replicator/replicator.go | 2 +- pkg/services/reputation/common/managers.go | 2 +- pkg/services/reputation/common/router/opts.go | 2 +- .../reputation/eigentrust/calculator/opts.go | 2 +- .../reputation/eigentrust/controller/opts.go | 2 +- .../reputation/local/controller/calls.go | 6 +++--- .../reputation/local/controller/opts.go | 2 +- .../session/storage/persistent/options.go | 7 ++++--- .../session/storage/persistent/storage.go | 3 ++- pkg/services/tree/options.go | 6 +++--- pkg/services/tree/service.go | 3 ++- pkg/services/tree/signature_test.go | 3 ++- pkg/util/logger/logger.go | 19 +++++++++++++------ pkg/util/logger/test/logger.go | 7 +++++-- 83 files changed, 207 insertions(+), 156 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 91f89a01..74941a7f 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -289,7 +289,7 @@ type internals struct { appCfg *config.Config - log *zap.Logger + log *logger.Logger wg *sync.WaitGroup workers []worker diff --git a/cmd/neofs-node/grpc.go b/cmd/neofs-node/grpc.go index 1521c560..b60d4c2b 100644 --- a/cmd/neofs-node/grpc.go +++ b/cmd/neofs-node/grpc.go @@ -92,7 +92,7 @@ func serveGRPC(c *cfg) { } func stopGRPC(name string, s *grpc.Server, l *logger.Logger) { - l = l.With(zap.String("name", name)) + l = &logger.Logger{Logger: l.With(zap.String("name", name))} l.Info("stopping gRPC server...") diff --git a/cmd/neofs-node/notificator.go b/cmd/neofs-node/notificator.go index 9c8502db..4f940187 100644 --- a/cmd/neofs-node/notificator.go +++ b/cmd/neofs-node/notificator.go @@ -10,6 +10,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap" "github.com/nspcc-dev/neofs-node/pkg/services/notificator" "github.com/nspcc-dev/neofs-node/pkg/services/notificator/nats" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" @@ -17,7 +18,7 @@ import ( type notificationSource struct { e *engine.StorageEngine - l *zap.Logger + l *logger.Logger defaultTopic string } @@ -92,7 +93,7 @@ func (n *notificationSource) processAddress( } type notificationWriter struct { - l *zap.Logger + l *logger.Logger w *nats.Writer } diff --git a/cmd/neofs-node/reputation.go b/cmd/neofs-node/reputation.go index 2b4f04f1..620ea466 100644 --- a/cmd/neofs-node/reputation.go +++ b/cmd/neofs-node/reputation.go @@ -60,8 +60,8 @@ func initReputationService(c *cfg) { Storage: consumerStorage, } - localTrustLogger := c.log.With(zap.String("trust_type", "local")) - intermediateTrustLogger := c.log.With(zap.String("trust_type", "intermediate")) + localTrustLogger := &logger.Logger{Logger: c.log.With(zap.String("trust_type", "local"))} + intermediateTrustLogger := &logger.Logger{Logger: c.log.With(zap.String("trust_type", "intermediate"))} localTrustStorage := &localreputation.TrustStorage{ Log: localTrustLogger, diff --git a/cmd/neofs-node/reputation/intermediate/contract.go b/cmd/neofs-node/reputation/intermediate/contract.go index 4a3e25c1..f4259963 100644 --- a/cmd/neofs-node/reputation/intermediate/contract.go +++ b/cmd/neofs-node/reputation/intermediate/contract.go @@ -133,7 +133,7 @@ type FinalWriterOption func(*finalWriterOptions) func defaultFinalWriterOptionsOpts() *finalWriterOptions { return &finalWriterOptions{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/innerring/blocktimer.go b/pkg/innerring/blocktimer.go index 0fe4daed..66fde250 100644 --- a/pkg/innerring/blocktimer.go +++ b/pkg/innerring/blocktimer.go @@ -10,6 +10,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" "github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/timer" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap" ) @@ -28,7 +29,7 @@ type ( newEpochHandler func() epochTimerArgs struct { - l *zap.Logger + l *logger.Logger newEpochHandlers []newEpochHandler diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 3dd31622..371fad58 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -47,6 +47,7 @@ import ( reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" util2 "github.com/nspcc-dev/neofs-node/pkg/util" utilConfig "github.com/nspcc-dev/neofs-node/pkg/util/config" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/precision" "github.com/nspcc-dev/neofs-node/pkg/util/state" "github.com/panjf2000/ants/v2" @@ -60,7 +61,7 @@ type ( // Server is the inner ring application structure, that contains all event // processors, shared variables and event handlers. Server struct { - log *zap.Logger + log *logger.Logger // event producers morphListener event.Listener @@ -128,7 +129,7 @@ type ( } chainParams struct { - log *zap.Logger + log *logger.Logger cfg *viper.Viper key *keys.PrivateKey name string @@ -316,7 +317,7 @@ func (s *Server) registerStarter(f func() error) { } // New creates instance of inner ring sever structure. -func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<- error) (*Server, error) { +func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan<- error) (*Server, error) { var err error server := &Server{log: log} @@ -956,7 +957,7 @@ func createListener(ctx context.Context, cli *client.Client, p *chainParams) (ev } listener, err := event.NewListener(event.ListenerParams{ - Logger: p.log.With(zap.String("chain", p.name)), + Logger: &logger.Logger{Logger: p.log.With(zap.String("chain", p.name))}, Subscriber: sub, WorkerPoolCapacity: listenerPoolCap, }) diff --git a/pkg/innerring/processors/alphabet/processor.go b/pkg/innerring/processors/alphabet/processor.go index 2642a860..5dc439ae 100644 --- a/pkg/innerring/processors/alphabet/processor.go +++ b/pkg/innerring/processors/alphabet/processor.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/morph/client" nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/event" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/panjf2000/ants/v2" "go.uber.org/zap" ) @@ -32,7 +33,7 @@ type ( // Processor of events produced for alphabet contracts in the sidechain. Processor struct { - log *zap.Logger + log *logger.Logger pool *ants.Pool alphabetContracts Contracts netmapClient *nmClient.Client @@ -43,7 +44,7 @@ type ( // Params of the processor constructor. Params struct { - Log *zap.Logger + Log *logger.Logger PoolSize int AlphabetContracts Contracts NetmapClient *nmClient.Client diff --git a/pkg/innerring/processors/audit/processor.go b/pkg/innerring/processors/audit/processor.go index 71923a59..6016e33a 100644 --- a/pkg/innerring/processors/audit/processor.go +++ b/pkg/innerring/processors/audit/processor.go @@ -12,8 +12,8 @@ import ( nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/services/audit" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/panjf2000/ants/v2" - "go.uber.org/zap" ) type ( @@ -40,7 +40,7 @@ type ( // Processor of events related to data audit. Processor struct { - log *zap.Logger + log *logger.Logger pool *ants.Pool irList Indexer sgSrc storagegroup.SGSource @@ -57,7 +57,7 @@ type ( // Params of the processor constructor. Params struct { - Log *zap.Logger + Log *logger.Logger NetmapClient *nmClient.Client ContainerClient *cntClient.Client IRList Indexer diff --git a/pkg/innerring/processors/balance/processor.go b/pkg/innerring/processors/balance/processor.go index f2e984d3..c31e6507 100644 --- a/pkg/innerring/processors/balance/processor.go +++ b/pkg/innerring/processors/balance/processor.go @@ -8,6 +8,7 @@ import ( neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs" "github.com/nspcc-dev/neofs-node/pkg/morph/event" balanceEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/balance" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/panjf2000/ants/v2" "go.uber.org/zap" ) @@ -25,7 +26,7 @@ type ( // Processor of events produced by balance contract in the morphchain. Processor struct { - log *zap.Logger + log *logger.Logger pool *ants.Pool neofsClient *neofscontract.Client balanceSC util.Uint160 @@ -35,7 +36,7 @@ type ( // Params of the processor constructor. Params struct { - Log *zap.Logger + Log *logger.Logger PoolSize int NeoFSClient *neofscontract.Client BalanceSC util.Uint160 diff --git a/pkg/innerring/processors/container/processor.go b/pkg/innerring/processors/container/processor.go index 039eb5fb..c572a19a 100644 --- a/pkg/innerring/processors/container/processor.go +++ b/pkg/innerring/processors/container/processor.go @@ -10,6 +10,7 @@ import ( morphsubnet "github.com/nspcc-dev/neofs-node/pkg/morph/client/subnet" "github.com/nspcc-dev/neofs-node/pkg/morph/event" containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/panjf2000/ants/v2" "go.uber.org/zap" ) @@ -22,7 +23,7 @@ type ( // Processor of events produced by container contract in the sidechain. Processor struct { - log *zap.Logger + log *logger.Logger pool *ants.Pool alphabetState AlphabetState cnrClient *container.Client // notary must be enabled @@ -34,7 +35,7 @@ type ( // Params of the processor constructor. Params struct { - Log *zap.Logger + Log *logger.Logger PoolSize int AlphabetState AlphabetState ContainerClient *container.Client diff --git a/pkg/innerring/processors/governance/processor.go b/pkg/innerring/processors/governance/processor.go index 3ac38289..e18a389f 100644 --- a/pkg/innerring/processors/governance/processor.go +++ b/pkg/innerring/processors/governance/processor.go @@ -12,8 +12,8 @@ import ( nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event/rolemanagement" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/panjf2000/ants/v2" - "go.uber.org/zap" ) // ProcessorPoolSize limits the pool size for governance Processor. Processor manages @@ -55,7 +55,7 @@ type ( // Processor of events related to governance in the network. Processor struct { - log *zap.Logger + log *logger.Logger pool *ants.Pool neofsClient *neofscontract.Client netmapClient *nmClient.Client @@ -75,7 +75,7 @@ type ( // Params of the processor constructor. Params struct { - Log *zap.Logger + Log *logger.Logger AlphabetState AlphabetState EpochState EpochState diff --git a/pkg/innerring/processors/neofs/processor.go b/pkg/innerring/processors/neofs/processor.go index f8e1613b..f156dea7 100644 --- a/pkg/innerring/processors/neofs/processor.go +++ b/pkg/innerring/processors/neofs/processor.go @@ -14,6 +14,7 @@ import ( nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/event" neofsEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/panjf2000/ants/v2" "go.uber.org/zap" ) @@ -36,7 +37,7 @@ type ( // Processor of events produced by neofs contract in main net. Processor struct { - log *zap.Logger + log *logger.Logger pool *ants.Pool neofsContract util.Uint160 balanceClient *balance.Client @@ -56,7 +57,7 @@ type ( // Params of the processor constructor. Params struct { - Log *zap.Logger + Log *logger.Logger PoolSize int NeoFSContract util.Uint160 NeoFSIDClient *neofsid.Client diff --git a/pkg/innerring/processors/netmap/processor.go b/pkg/innerring/processors/netmap/processor.go index 533bd30f..e2d37ff4 100644 --- a/pkg/innerring/processors/netmap/processor.go +++ b/pkg/innerring/processors/netmap/processor.go @@ -12,6 +12,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/morph/event" netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap" subnetEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/subnet" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/netmap" "github.com/panjf2000/ants/v2" "go.uber.org/zap" @@ -54,7 +55,7 @@ type ( // Processor of events produced by network map contract // and new epoch ticker, because it is related to contract. Processor struct { - log *zap.Logger + log *logger.Logger pool *ants.Pool epochTimer EpochTimerReseter epochState EpochState @@ -81,7 +82,7 @@ type ( // Params of the processor constructor. Params struct { - Log *zap.Logger + Log *logger.Logger PoolSize int NetmapClient *nmClient.Client EpochTimer EpochTimerReseter diff --git a/pkg/innerring/processors/reputation/processor.go b/pkg/innerring/processors/reputation/processor.go index 543cad53..54ce2a2b 100644 --- a/pkg/innerring/processors/reputation/processor.go +++ b/pkg/innerring/processors/reputation/processor.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/morph/event" reputationEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/panjf2000/ants/v2" "go.uber.org/zap" ) @@ -26,7 +27,7 @@ type ( // Processor of events produced by reputation contract. Processor struct { - log *zap.Logger + log *logger.Logger pool *ants.Pool epochState EpochState @@ -41,7 +42,7 @@ type ( // Params of the processor constructor. Params struct { - Log *zap.Logger + Log *logger.Logger PoolSize int EpochState EpochState AlphabetState AlphabetState diff --git a/pkg/innerring/processors/settlement/audit/calculate.go b/pkg/innerring/processors/settlement/audit/calculate.go index 38800a06..cc3d1253 100644 --- a/pkg/innerring/processors/settlement/audit/calculate.go +++ b/pkg/innerring/processors/settlement/audit/calculate.go @@ -53,9 +53,9 @@ var ( // Calculate calculates payments for audit results in a specific epoch of the network. // Wraps the results in a money transfer transaction and sends it to the network. func (c *Calculator) Calculate(p *CalculatePrm) { - log := c.opts.log.With( + log := &logger.Logger{Logger: c.opts.log.With( zap.Uint64("current epoch", p.Epoch), - ) + )} if p.Epoch == 0 { log.Info("settlements are ignored for zero epoch") @@ -104,10 +104,10 @@ func (c *Calculator) Calculate(p *CalculatePrm) { } func (c *Calculator) processResult(ctx *singleResultCtx) { - ctx.log = ctx.log.With( + ctx.log = &logger.Logger{Logger: ctx.log.With( zap.Stringer("cid", ctx.containerID()), zap.Uint64("audit epoch", ctx.auditResult.Epoch()), - ) + )} ctx.log.Debug("reading information about the container") diff --git a/pkg/innerring/processors/settlement/audit/calculator.go b/pkg/innerring/processors/settlement/audit/calculator.go index f460798b..0b005e3d 100644 --- a/pkg/innerring/processors/settlement/audit/calculator.go +++ b/pkg/innerring/processors/settlement/audit/calculator.go @@ -22,7 +22,7 @@ type options struct { func defaultOptions() *options { return &options{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/innerring/processors/settlement/basic/context.go b/pkg/innerring/processors/settlement/basic/context.go index 4c9c32eb..6b5b4339 100644 --- a/pkg/innerring/processors/settlement/basic/context.go +++ b/pkg/innerring/processors/settlement/basic/context.go @@ -7,8 +7,8 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/common" "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/user" - "go.uber.org/zap" ) type ( @@ -28,7 +28,7 @@ type ( IncomeSettlementContext struct { mu sync.Mutex // lock to prevent collection and distribution in the same time - log *zap.Logger + log *logger.Logger epoch uint64 rate RateFetcher @@ -46,7 +46,7 @@ type ( } IncomeSettlementContextPrms struct { - Log *zap.Logger + Log *logger.Logger Epoch uint64 Rate RateFetcher Estimations EstimationFetcher diff --git a/pkg/innerring/processors/settlement/calls.go b/pkg/innerring/processors/settlement/calls.go index dae6ae16..6ec42abb 100644 --- a/pkg/innerring/processors/settlement/calls.go +++ b/pkg/innerring/processors/settlement/calls.go @@ -2,6 +2,7 @@ package settlement import ( "github.com/nspcc-dev/neofs-node/pkg/morph/event" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap" ) @@ -12,9 +13,9 @@ func (p *Processor) HandleAuditEvent(e event.Event) { epoch := ev.Epoch() - log := p.log.With( + log := &logger.Logger{Logger: p.log.With( zap.Uint64("epoch", epoch), - ) + )} log.Info("new audit settlement event") diff --git a/pkg/innerring/processors/settlement/opts.go b/pkg/innerring/processors/settlement/opts.go index 8196f55f..73b24b6f 100644 --- a/pkg/innerring/processors/settlement/opts.go +++ b/pkg/innerring/processors/settlement/opts.go @@ -19,7 +19,7 @@ func defaultOptions() *options { return &options{ poolSize: poolSize, - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/innerring/rpc.go b/pkg/innerring/rpc.go index 4f229e26..b649e839 100644 --- a/pkg/innerring/rpc.go +++ b/pkg/innerring/rpc.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/network/cache" "github.com/nspcc-dev/neofs-node/pkg/services/audit/auditor" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" "github.com/nspcc-dev/neofs-sdk-go/netmap" "github.com/nspcc-dev/neofs-sdk-go/object" @@ -23,7 +24,7 @@ import ( type ( ClientCache struct { - log *zap.Logger + log *logger.Logger cache interface { Get(clientcore.NodeInfo) (clientcore.Client, error) CloseAll() @@ -34,7 +35,7 @@ type ( } clientCacheParams struct { - Log *zap.Logger + Log *logger.Logger Key *ecdsa.PrivateKey AllowExternal bool diff --git a/pkg/local_object_storage/blobovnicza/blobovnicza.go b/pkg/local_object_storage/blobovnicza/blobovnicza.go index 4466f58f..8bd1d68f 100644 --- a/pkg/local_object_storage/blobovnicza/blobovnicza.go +++ b/pkg/local_object_storage/blobovnicza/blobovnicza.go @@ -51,7 +51,7 @@ func defaultCfg(с *cfg) { }, fullSizeLimit: 1 << 30, // 1GB objSizeLimit: 1 << 20, // 1MB - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } @@ -102,7 +102,7 @@ func WithFullSizeLimit(lim uint64) Option { // WithLogger returns an option to specify Blobovnicza's logger. func WithLogger(l *logger.Logger) Option { return func(c *cfg) { - c.log = l.With(zap.String("component", "Blobovnicza")) + c.log = &logger.Logger{Logger: l.With(zap.String("component", "Blobovnicza"))} } } diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go index c0d623d0..b331a13b 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza_test.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/internal/blobstortest" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -135,7 +136,7 @@ func testFillOrder(t *testing.T, depth uint64) { p, err := os.MkdirTemp("", "*") require.NoError(t, err) b := NewBlobovniczaTree( - WithLogger(zaptest.NewLogger(t)), + WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), WithObjectSizeLimit(2048), WithBlobovniczaShallowWidth(3), WithBlobovniczaShallowDepth(depth), diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/generic_test.go b/pkg/local_object_storage/blobstor/blobovniczatree/generic_test.go index 5b60270f..29a39774 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/generic_test.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/generic_test.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/internal/blobstortest" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap/zaptest" ) @@ -18,7 +19,7 @@ func TestGeneric(t *testing.T) { helper := func(t *testing.T, dir string) common.Storage { return NewBlobovniczaTree( - WithLogger(zaptest.NewLogger(t)), + WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), WithObjectSizeLimit(maxObjectSize), WithBlobovniczaShallowWidth(2), WithBlobovniczaShallowDepth(2), @@ -51,7 +52,7 @@ func TestControl(t *testing.T) { newTree := func(t *testing.T) common.Storage { dir := filepath.Join(t.Name(), strconv.Itoa(n)) return NewBlobovniczaTree( - WithLogger(zaptest.NewLogger(t)), + WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), WithObjectSizeLimit(maxObjectSize), WithBlobovniczaShallowWidth(2), WithBlobovniczaShallowDepth(2), diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/option.go b/pkg/local_object_storage/blobstor/blobovniczatree/option.go index f5ed19df..dca75569 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/option.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/option.go @@ -5,11 +5,12 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/compression" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap" ) type cfg struct { - log *zap.Logger + log *logger.Logger perm fs.FileMode readOnly bool rootPath string @@ -31,7 +32,7 @@ const ( func initConfig(c *cfg) { *c = cfg{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, perm: defaultPerm, openedCacheSize: defaultOpenedCacheSize, blzShallowDepth: defaultBlzShallowDepth, @@ -39,7 +40,7 @@ func initConfig(c *cfg) { } } -func WithLogger(l *zap.Logger) Option { +func WithLogger(l *logger.Logger) Option { return func(c *cfg) { c.log = l c.blzOpts = append(c.blzOpts, blobovnicza.WithLogger(l)) diff --git a/pkg/local_object_storage/blobstor/blobstor.go b/pkg/local_object_storage/blobstor/blobstor.go index 0480db0d..fdd1949b 100644 --- a/pkg/local_object_storage/blobstor/blobstor.go +++ b/pkg/local_object_storage/blobstor/blobstor.go @@ -46,7 +46,7 @@ type cfg struct { } func initConfig(c *cfg) { - c.log = zap.L() + c.log = &logger.Logger{Logger: zap.L()} } // New creates, initializes and returns new BlobStor instance. @@ -66,7 +66,7 @@ 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) { +func (b *BlobStor) SetLogger(l *logger.Logger) { b.log = l } @@ -80,7 +80,7 @@ func WithStorages(st []SubStorage) Option { // WithLogger returns option to specify BlobStor's logger. func WithLogger(l *logger.Logger) Option { return func(c *cfg) { - c.log = l.With(zap.String("component", "BlobStor")) + c.log = &logger.Logger{Logger: l.With(zap.String("component", "BlobStor"))} } } diff --git a/pkg/local_object_storage/engine/delete_test.go b/pkg/local_object_storage/engine/delete_test.go index 0fde179d..72e6b3fa 100644 --- a/pkg/local_object_storage/engine/delete_test.go +++ b/pkg/local_object_storage/engine/delete_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/nspcc-dev/neofs-node/pkg/core/object" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" @@ -52,7 +53,7 @@ func TestDeleteBigObject(t *testing.T) { s3 := testNewShard(t, 3) e := testNewEngineWithShards(s1, s2, s3) - e.log = zaptest.NewLogger(t) + e.log = &logger.Logger{Logger: zaptest.NewLogger(t)} defer e.Close() for i := range children { diff --git a/pkg/local_object_storage/engine/engine.go b/pkg/local_object_storage/engine/engine.go index 64041f62..463f2a8f 100644 --- a/pkg/local_object_storage/engine/engine.go +++ b/pkg/local_object_storage/engine/engine.go @@ -78,7 +78,7 @@ type cfg struct { func defaultCfg() *cfg { return &cfg{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, shardPoolSize: 20, } diff --git a/pkg/local_object_storage/engine/engine_test.go b/pkg/local_object_storage/engine/engine_test.go index bb211561..8911e3eb 100644 --- a/pkg/local_object_storage/engine/engine_test.go +++ b/pkg/local_object_storage/engine/engine_test.go @@ -12,6 +12,7 @@ import ( meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/checksum" checksumtest "github.com/nspcc-dev/neofs-sdk-go/checksum/test" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" @@ -121,7 +122,7 @@ func testNewShard(t testing.TB, id int) *shard.Shard { s := shard.New( shard.WithID(sid), - shard.WithLogger(zap.L()), + shard.WithLogger(&logger.Logger{Logger: zap.L()}), shard.WithBlobStorOptions( blobstor.WithStorages( newStorages(filepath.Join(t.Name(), fmt.Sprintf("%d.blobstor", id)), diff --git a/pkg/local_object_storage/engine/error_test.go b/pkg/local_object_storage/engine/error_test.go index ccbe8c04..b6bbc1bc 100644 --- a/pkg/local_object_storage/engine/error_test.go +++ b/pkg/local_object_storage/engine/error_test.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" @@ -32,7 +33,7 @@ func newEngineWithErrorThreshold(t testing.TB, dir string, errThreshold uint32) } e := New( - WithLogger(zaptest.NewLogger(t)), + WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), WithShardPoolSize(1), WithErrorThreshold(errThreshold)) @@ -41,7 +42,7 @@ func newEngineWithErrorThreshold(t testing.TB, dir string, errThreshold uint32) for i := range ids { ids[i], err = e.AddShard( - shard.WithLogger(zaptest.NewLogger(t)), + shard.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), shard.WithBlobStorOptions( blobstor.WithStorages(newStorages(filepath.Join(dir, strconv.Itoa(i)), errSmallSize))), shard.WithMetaBaseOptions( diff --git a/pkg/local_object_storage/engine/evacuate_test.go b/pkg/local_object_storage/engine/evacuate_test.go index 29563217..9c0a84b8 100644 --- a/pkg/local_object_storage/engine/evacuate_test.go +++ b/pkg/local_object_storage/engine/evacuate_test.go @@ -14,6 +14,7 @@ import ( meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -27,14 +28,14 @@ func newEngineEvacuate(t *testing.T, shardNum int, objPerShard int) (*StorageEng t.Cleanup(func() { _ = os.RemoveAll(dir) }) e := New( - WithLogger(zaptest.NewLogger(t)), + WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), WithShardPoolSize(1)) ids := make([]*shard.ID, shardNum) for i := range ids { ids[i], err = e.AddShard( - shard.WithLogger(zaptest.NewLogger(t)), + shard.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), shard.WithBlobStorOptions( blobstor.WithStorages([]blobstor.SubStorage{{ Storage: fstree.New( diff --git a/pkg/local_object_storage/metabase/db.go b/pkg/local_object_storage/metabase/db.go index 29ba942c..acf6031f 100644 --- a/pkg/local_object_storage/metabase/db.go +++ b/pkg/local_object_storage/metabase/db.go @@ -69,7 +69,7 @@ func defaultCfg() *cfg { }, boltBatchDelay: bbolt.DefaultMaxBatchDelay, boltBatchSize: bbolt.DefaultMaxBatchSize, - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } @@ -288,7 +288,7 @@ 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) { +func (db *DB) SetLogger(l *logger.Logger) { db.log = l } diff --git a/pkg/local_object_storage/shard/control_test.go b/pkg/local_object_storage/shard/control_test.go index eb9d2a3f..d0849441 100644 --- a/pkg/local_object_storage/shard/control_test.go +++ b/pkg/local_object_storage/shard/control_test.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" @@ -36,7 +37,7 @@ func TestShardOpen(t *testing.T) { newShard := func() *Shard { return New( - WithLogger(zaptest.NewLogger(t)), + WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), WithBlobStorOptions( blobstor.WithStorages([]blobstor.SubStorage{ { diff --git a/pkg/local_object_storage/shard/dump_test.go b/pkg/local_object_storage/shard/dump_test.go index 3cf0004e..2d7bda59 100644 --- a/pkg/local_object_storage/shard/dump_test.go +++ b/pkg/local_object_storage/shard/dump_test.go @@ -18,6 +18,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -52,7 +53,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) { []writecache.Option{ writecache.WithSmallObjectSize(wcSmallObjectSize), writecache.WithMaxObjectSize(wcBigObjectSize), - writecache.WithLogger(zaptest.NewLogger(t)), + writecache.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), }, nil) } diff --git a/pkg/local_object_storage/shard/gc.go b/pkg/local_object_storage/shard/gc.go index b61ed7ca..04f72a97 100644 --- a/pkg/local_object_storage/shard/gc.go +++ b/pkg/local_object_storage/shard/gc.go @@ -85,7 +85,7 @@ type gcCfg struct { func defaultGCCfg() *gcCfg { return &gcCfg{ removerInterval: 10 * time.Second, - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, workerPoolInit: func(int) util.WorkerPool { return nil }, diff --git a/pkg/local_object_storage/shard/id.go b/pkg/local_object_storage/shard/id.go index ef7614f6..59211281 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" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap" ) @@ -44,7 +45,7 @@ func (s *Shard) UpdateID() (err error) { s.info.ID = NewIDFromBytes(id) } - s.log = s.log.With(zap.String("shard_id", s.info.ID.String())) + s.log = &logger.Logger{Logger: s.log.With(zap.String("shard_id", s.info.ID.String()))} s.metaBase.SetLogger(s.log) s.blobStor.SetLogger(s.log) if s.hasWriteCache() { diff --git a/pkg/local_object_storage/shard/lock_test.go b/pkg/local_object_storage/shard/lock_test.go index a4b55276..09084d5e 100644 --- a/pkg/local_object_storage/shard/lock_test.go +++ b/pkg/local_object_storage/shard/lock_test.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" @@ -24,7 +25,7 @@ func TestShard_Lock(t *testing.T) { rootPath := t.TempDir() opts := []shard.Option{ - shard.WithLogger(zap.NewNop()), + shard.WithLogger(&logger.Logger{Logger: zap.NewNop()}), shard.WithBlobStorOptions( blobstor.WithStorages([]blobstor.SubStorage{ { diff --git a/pkg/local_object_storage/shard/range_test.go b/pkg/local_object_storage/shard/range_test.go index fd7d324a..1266ae20 100644 --- a/pkg/local_object_storage/shard/range_test.go +++ b/pkg/local_object_storage/shard/range_test.go @@ -12,6 +12,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" "github.com/stretchr/testify/require" @@ -69,7 +70,7 @@ func testShardGetRange(t *testing.T, hasWriteCache bool) { []blobstor.Option{blobstor.WithStorages([]blobstor.SubStorage{ { Storage: blobovniczatree.NewBlobovniczaTree( - blobovniczatree.WithLogger(zaptest.NewLogger(t)), + blobovniczatree.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), blobovniczatree.WithRootPath(filepath.Join(t.TempDir(), "blob", "blobovnicza")), blobovniczatree.WithBlobovniczaShallowDepth(1), blobovniczatree.WithBlobovniczaShallowWidth(1)), diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index 8cdad396..cbad4db9 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -98,7 +98,7 @@ type cfg struct { func defaultCfg() *cfg { return &cfg{ rmBatchSize: 100, - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, gcCfg: defaultGCCfg(), } } diff --git a/pkg/local_object_storage/shard/shard_test.go b/pkg/local_object_storage/shard/shard_test.go index 483e099f..35d8a72b 100644 --- a/pkg/local_object_storage/shard/shard_test.go +++ b/pkg/local_object_storage/shard/shard_test.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/checksum" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" @@ -47,11 +48,11 @@ func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts if bsOpts == nil { bsOpts = []blobstor.Option{ - blobstor.WithLogger(zaptest.NewLogger(t)), + blobstor.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), blobstor.WithStorages([]blobstor.SubStorage{ { Storage: blobovniczatree.NewBlobovniczaTree( - blobovniczatree.WithLogger(zaptest.NewLogger(t)), + blobovniczatree.WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), blobovniczatree.WithRootPath(filepath.Join(rootPath, "blob", "blobovnicza")), blobovniczatree.WithBlobovniczaShallowDepth(1), blobovniczatree.WithBlobovniczaShallowWidth(1)), @@ -68,7 +69,7 @@ func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts } opts := []shard.Option{ - shard.WithLogger(zap.L()), + shard.WithLogger(&logger.Logger{Logger: zap.L()}), shard.WithBlobStorOptions(bsOpts...), shard.WithMetaBaseOptions( meta.WithPath(filepath.Join(rootPath, "meta")), diff --git a/pkg/local_object_storage/writecache/flush_test.go b/pkg/local_object_storage/writecache/flush_test.go index b5dbd48e..e98cc941 100644 --- a/pkg/local_object_storage/writecache/flush_test.go +++ b/pkg/local_object_storage/writecache/flush_test.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" checksumtest "github.com/nspcc-dev/neofs-sdk-go/checksum/test" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" @@ -53,7 +54,7 @@ func TestFlush(t *testing.T) { require.NoError(t, bs.Init()) wc := New( - WithLogger(zaptest.NewLogger(t)), + WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), WithPath(filepath.Join(dir, "writecache")), WithSmallObjectSize(smallSize), WithMetabase(mb), diff --git a/pkg/local_object_storage/writecache/generic_test.go b/pkg/local_object_storage/writecache/generic_test.go index 4e97b21e..0fb39e59 100644 --- a/pkg/local_object_storage/writecache/generic_test.go +++ b/pkg/local_object_storage/writecache/generic_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/storagetest" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" ) @@ -20,7 +21,7 @@ func TestGeneric(t *testing.T) { dir := filepath.Join(t.Name(), strconv.Itoa(n)) require.NoError(t, os.MkdirAll(dir, os.ModePerm)) return New( - WithLogger(zaptest.NewLogger(t)), + WithLogger(&logger.Logger{Logger: zaptest.NewLogger(t)}), WithFlushWorkersCount(2), WithPath(dir)) } diff --git a/pkg/local_object_storage/writecache/options.go b/pkg/local_object_storage/writecache/options.go index d6cb7567..0e3fd05f 100644 --- a/pkg/local_object_storage/writecache/options.go +++ b/pkg/local_object_storage/writecache/options.go @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" "go.uber.org/zap" ) @@ -27,7 +28,7 @@ type blob interface { } type options struct { - log *zap.Logger + log *logger.Logger // path is a path to a directory for write-cache. path string // blobstor is the main persistent storage. @@ -52,9 +53,9 @@ type options struct { } // WithLogger sets logger. -func WithLogger(log *zap.Logger) Option { +func WithLogger(log *logger.Logger) Option { return func(o *options) { - o.log = log.With(zap.String("component", "WriteCache")) + o.log = &logger.Logger{Logger: log.With(zap.String("component", "WriteCache"))} } } diff --git a/pkg/local_object_storage/writecache/writecache.go b/pkg/local_object_storage/writecache/writecache.go index 8d2f0d75..4d53c8a2 100644 --- a/pkg/local_object_storage/writecache/writecache.go +++ b/pkg/local_object_storage/writecache/writecache.go @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" @@ -26,7 +27,7 @@ type Cache interface { Iterate(IterationPrm) error Put(common.PutPrm) (common.PutRes, error) SetMode(mode.Mode) error - SetLogger(*zap.Logger) + SetLogger(*logger.Logger) DumpInfo() Info Flush(bool) error @@ -84,7 +85,7 @@ func New(opts ...Option) Cache { compressFlags: make(map[string]struct{}), options: options{ - log: zap.NewNop(), + log: &logger.Logger{Logger: zap.NewNop()}, maxObjectSize: defaultMaxObjectSize, smallObjectSize: defaultSmallObjectSize, workersCount: defaultFlushWorkersCount, @@ -108,7 +109,7 @@ func New(opts ...Option) Cache { } // SetLogger sets logger. It is used after the shard ID was generated to use it in logs. -func (c *cache) SetLogger(l *zap.Logger) { +func (c *cache) SetLogger(l *logger.Logger) { c.log = l } diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 699b16aa..45de2e90 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -55,7 +55,7 @@ func defaultConfig() *cfg { return &cfg{ ctx: context.Background(), dialTimeout: defaultDialTimeout, - logger: zap.L(), + logger: &logger.Logger{Logger: zap.L()}, waitInterval: defaultWaitInterval, signer: &transaction.Signer{ Scopes: transaction.Global, @@ -75,7 +75,7 @@ func defaultConfig() *cfg { // - blockchain network type: netmode.PrivNet; // - signer with the global scope; // - wait interval: 500ms; -// - logger: zap.L(). +// - logger: &logger.Logger{Logger: zap.L()}. // // If desired option satisfies the default value, it can be omitted. // If multiple options of the same config value are supplied, @@ -238,7 +238,7 @@ func WithDialTimeout(dur time.Duration) Option { // // Ignores nil value. // -// If option not provided, zap.L() is used. +// If option not provided, &logger.Logger{Logger: zap.L()} is used. func WithLogger(logger *logger.Logger) Option { return func(c *cfg) { if logger != nil { diff --git a/pkg/morph/event/listener.go b/pkg/morph/event/listener.go index af6ed304..0c0a845b 100644 --- a/pkg/morph/event/listener.go +++ b/pkg/morph/event/listener.go @@ -12,6 +12,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/subscriber" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/panjf2000/ants/v2" "go.uber.org/zap" ) @@ -84,7 +85,7 @@ type Listener interface { // ListenerParams is a group of parameters // for Listener constructor. type ListenerParams struct { - Logger *zap.Logger + Logger *logger.Logger Subscriber subscriber.Subscriber @@ -107,7 +108,7 @@ type listener struct { notaryHandlers map[notaryRequestTypes]Handler notaryMainTXSigner util.Uint160 // filter for notary subscription - log *zap.Logger + log *logger.Logger subscriber subscriber.Subscriber diff --git a/pkg/morph/event/utils.go b/pkg/morph/event/utils.go index cd37a0f3..5e6a3370 100644 --- a/pkg/morph/event/utils.go +++ b/pkg/morph/event/utils.go @@ -10,6 +10,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" util2 "github.com/nspcc-dev/neofs-node/pkg/util" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap" ) @@ -81,7 +82,7 @@ func (s typeValue) GetType() Type { } // WorkerPoolHandler sets closure over worker pool w with passed handler h. -func WorkerPoolHandler(w util2.WorkerPool, h Handler, log *zap.Logger) Handler { +func WorkerPoolHandler(w util2.WorkerPool, h Handler, log *logger.Logger) Handler { return func(e Event) { err := w.Submit(func() { h(e) diff --git a/pkg/morph/subscriber/subscriber.go b/pkg/morph/subscriber/subscriber.go index cf5b6ccd..3d9b57ea 100644 --- a/pkg/morph/subscriber/subscriber.go +++ b/pkg/morph/subscriber/subscriber.go @@ -12,6 +12,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/neorpc/result" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/morph/client" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap" ) @@ -27,7 +28,7 @@ type ( subscriber struct { *sync.RWMutex - log *zap.Logger + log *logger.Logger client *client.Client notifyChan chan *state.ContainedNotificationEvent @@ -39,7 +40,7 @@ type ( // Params is a group of Subscriber constructor parameters. Params struct { - Log *zap.Logger + Log *logger.Logger StartFromBlock uint32 Client *client.Client } diff --git a/pkg/services/audit/auditor/context.go b/pkg/services/audit/auditor/context.go index b20adf4c..9727065e 100644 --- a/pkg/services/audit/auditor/context.go +++ b/pkg/services/audit/auditor/context.go @@ -191,9 +191,9 @@ func (c *Context) init() { c.headResponses = make(map[string]shortHeader) - c.log = c.log.With( + c.log = &logger.Logger{Logger: c.log.With( zap.Stringer("container ID", c.task.ContainerID()), - ) + )} } func (c *Context) expired() bool { diff --git a/pkg/services/audit/taskmanager/manager.go b/pkg/services/audit/taskmanager/manager.go index b04bf4df..44b14c3f 100644 --- a/pkg/services/audit/taskmanager/manager.go +++ b/pkg/services/audit/taskmanager/manager.go @@ -34,7 +34,7 @@ type cfg struct { func defaultCfg() *cfg { return &cfg{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } @@ -54,7 +54,7 @@ func New(opts ...Option) *Manager { // WithLogger returns option to specify Manager's logger. func WithLogger(l *logger.Logger) Option { return func(c *cfg) { - c.log = l.With(zap.String("component", "Audit task manager")) + c.log = &logger.Logger{Logger: l.With(zap.String("component", "Audit task manager"))} c.ctxPrm.SetLogger(l) } } diff --git a/pkg/services/container/announcement/load/controller/calls.go b/pkg/services/container/announcement/load/controller/calls.go index b209ef74..056c3155 100644 --- a/pkg/services/container/announcement/load/controller/calls.go +++ b/pkg/services/container/announcement/load/controller/calls.go @@ -125,9 +125,9 @@ func (c *Controller) acquireAnnouncement(prm StartPrm) *announceContext { c.announceMtx.Unlock() - log := c.opts.log.With( + log := &logger.Logger{Logger: c.opts.log.With( zap.Uint64("epoch", prm.Epoch), - ) + )} if ctx == nil { log.Debug("announcement is already started") @@ -217,9 +217,9 @@ func (c *Controller) acquireReport(prm StopPrm) *stopContext { c.reportMtx.Unlock() - log := c.opts.log.With( + log := &logger.Logger{Logger: c.opts.log.With( zap.Uint64("epoch", prm.Epoch), - ) + )} if ctx == nil { log.Debug("report is already started") diff --git a/pkg/services/container/announcement/load/controller/opts.go b/pkg/services/container/announcement/load/controller/opts.go index 408bfe15..b4ca55ed 100644 --- a/pkg/services/container/announcement/load/controller/opts.go +++ b/pkg/services/container/announcement/load/controller/opts.go @@ -14,7 +14,7 @@ type options struct { func defaultOpts() *options { return &options{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/services/container/announcement/load/route/opts.go b/pkg/services/container/announcement/load/route/opts.go index abbc385c..91a9afcc 100644 --- a/pkg/services/container/announcement/load/route/opts.go +++ b/pkg/services/container/announcement/load/route/opts.go @@ -14,7 +14,7 @@ type options struct { func defaultOpts() *options { return &options{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/services/notificator/nats/options.go b/pkg/services/notificator/nats/options.go index 278705ac..52aac811 100644 --- a/pkg/services/notificator/nats/options.go +++ b/pkg/services/notificator/nats/options.go @@ -4,7 +4,7 @@ import ( "time" "github.com/nats-io/nats.go" - "go.uber.org/zap" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" ) func WithClientCert(certPath, keyPath string) Option { @@ -31,7 +31,7 @@ func WithConnectionName(name string) Option { } } -func WithLogger(logger *zap.Logger) Option { +func WithLogger(logger *logger.Logger) Option { return func(o *opts) { o.log = logger } diff --git a/pkg/services/notificator/nats/service.go b/pkg/services/notificator/nats/service.go index a273217e..f54f920b 100644 --- a/pkg/services/notificator/nats/service.go +++ b/pkg/services/notificator/nats/service.go @@ -7,6 +7,7 @@ import ( "sync" "github.com/nats-io/nats.go" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -29,7 +30,7 @@ type Writer struct { } type opts struct { - log *zap.Logger + log *logger.Logger nOpts []nats.Option } @@ -85,7 +86,7 @@ func New(oo ...Option) *Writer { m: &sync.RWMutex{}, createdStreams: make(map[string]struct{}), opts: opts{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, nOpts: make([]nats.Option, 0, len(oo)+3), }, } diff --git a/pkg/services/notificator/service.go b/pkg/services/notificator/service.go index e60af0f7..68885ca4 100644 --- a/pkg/services/notificator/service.go +++ b/pkg/services/notificator/service.go @@ -3,6 +3,7 @@ package notificator import ( "fmt" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -12,11 +13,11 @@ import ( type Prm struct { writer NotificationWriter notificationSource NotificationSource - logger *zap.Logger + logger *logger.Logger } // SetLogger sets a logger. -func (prm *Prm) SetLogger(v *zap.Logger) *Prm { +func (prm *Prm) SetLogger(v *logger.Logger) *Prm { prm.logger = v return prm } @@ -43,7 +44,7 @@ func (prm *Prm) SetNotificationSource(v NotificationSource) *Prm { type Notificator struct { w NotificationWriter ns NotificationSource - l *zap.Logger + l *logger.Logger } // New creates, initializes and returns the Notificator instance. diff --git a/pkg/services/object/acl/v2/classifier.go b/pkg/services/object/acl/v2/classifier.go index 4888de22..31e5d57f 100644 --- a/pkg/services/object/acl/v2/classifier.go +++ b/pkg/services/object/acl/v2/classifier.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" core "github.com/nspcc-dev/neofs-node/pkg/core/netmap" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/container" "github.com/nspcc-dev/neofs-sdk-go/container/acl" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" @@ -13,7 +14,7 @@ import ( ) type senderClassifier struct { - log *zap.Logger + log *logger.Logger innerRing InnerRingFetcher netmap core.Source } diff --git a/pkg/services/object/acl/v2/opts.go b/pkg/services/object/acl/v2/opts.go index 40d14c59..532f7ab3 100644 --- a/pkg/services/object/acl/v2/opts.go +++ b/pkg/services/object/acl/v2/opts.go @@ -4,11 +4,11 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object" - "go.uber.org/zap" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" ) // WithLogger returns option to set logger. -func WithLogger(v *zap.Logger) Option { +func WithLogger(v *logger.Logger) Option { return func(c *cfg) { c.log = v } diff --git a/pkg/services/object/acl/v2/service.go b/pkg/services/object/acl/v2/service.go index 0680c418..b2f7815a 100644 --- a/pkg/services/object/acl/v2/service.go +++ b/pkg/services/object/acl/v2/service.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/services/object" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/container/acl" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -57,7 +58,7 @@ type searchStreamBasicChecker struct { type Option func(*cfg) type cfg struct { - log *zap.Logger + log *logger.Logger containers container.Source @@ -72,7 +73,7 @@ type cfg struct { func defaultCfg() *cfg { return &cfg{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/services/object/delete/exec.go b/pkg/services/object/delete/exec.go index 9c1dcb62..db70125b 100644 --- a/pkg/services/object/delete/exec.go +++ b/pkg/services/object/delete/exec.go @@ -42,13 +42,13 @@ const ( ) func (exec *execCtx) setLogger(l *logger.Logger) { - exec.log = l.With( + exec.log = &logger.Logger{Logger: l.With( zap.String("request", "DELETE"), zap.Stringer("address", exec.address()), zap.Bool("local", exec.isLocal()), zap.Bool("with session", exec.prm.common.SessionToken() != nil), zap.Bool("with bearer", exec.prm.common.BearerToken() != nil), - ) + )} } func (exec execCtx) context() context.Context { diff --git a/pkg/services/object/delete/service.go b/pkg/services/object/delete/service.go index a66f16dd..8e8aa523 100644 --- a/pkg/services/object/delete/service.go +++ b/pkg/services/object/delete/service.go @@ -62,7 +62,7 @@ type cfg struct { func defaultCfg() *cfg { return &cfg{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } @@ -83,7 +83,7 @@ func New(opts ...Option) *Service { // WithLogger returns option to specify Delete service's logger. func WithLogger(l *logger.Logger) Option { return func(c *cfg) { - c.log = l.With(zap.String("component", "Object.Delete service")) + c.log = &logger.Logger{Logger: l.With(zap.String("component", "Object.Delete service"))} } } diff --git a/pkg/services/object/get/exec.go b/pkg/services/object/get/exec.go index bbb901ad..136830e7 100644 --- a/pkg/services/object/get/exec.go +++ b/pkg/services/object/get/exec.go @@ -73,14 +73,14 @@ func (exec *execCtx) setLogger(l *logger.Logger) { req = "GET_RANGE" } - exec.log = l.With( + exec.log = &logger.Logger{Logger: l.With( zap.String("request", req), zap.Stringer("address", exec.address()), zap.Bool("raw", exec.isRaw()), zap.Bool("local", exec.isLocal()), zap.Bool("with session", exec.prm.common.SessionToken() != nil), zap.Bool("with bearer", exec.prm.common.BearerToken() != nil), - ) + )} } func (exec execCtx) context() context.Context { diff --git a/pkg/services/object/get/service.go b/pkg/services/object/get/service.go index aeda2b15..c4d32865 100644 --- a/pkg/services/object/get/service.go +++ b/pkg/services/object/get/service.go @@ -52,7 +52,7 @@ type cfg struct { func defaultCfg() *cfg { return &cfg{ assembly: true, - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, localStorage: new(storageEngineWrapper), clientCache: new(clientCacheWrapper), } @@ -75,7 +75,7 @@ func New(opts ...Option) *Service { // WithLogger returns option to specify Get service's logger. func WithLogger(l *logger.Logger) Option { return func(c *cfg) { - c.log = l.With(zap.String("component", "Object.Get service")) + c.log = &logger.Logger{Logger: l.With(zap.String("component", "Object.Get service"))} } } diff --git a/pkg/services/object/put/service.go b/pkg/services/object/put/service.go index 65a86706..5dcfd568 100644 --- a/pkg/services/object/put/service.go +++ b/pkg/services/object/put/service.go @@ -61,7 +61,7 @@ func defaultCfg() *cfg { return &cfg{ remotePool: util.NewPseudoWorkerPool(), localPool: util.NewPseudoWorkerPool(), - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/services/object/search/exec.go b/pkg/services/object/search/exec.go index 4e7100f0..28282446 100644 --- a/pkg/services/object/search/exec.go +++ b/pkg/services/object/search/exec.go @@ -42,13 +42,13 @@ func (exec *execCtx) prepare() { } func (exec *execCtx) setLogger(l *logger.Logger) { - exec.log = l.With( + exec.log = &logger.Logger{Logger: l.With( zap.String("request", "SEARCH"), zap.Stringer("container", exec.containerID()), zap.Bool("local", exec.isLocal()), zap.Bool("with session", exec.prm.common.SessionToken() != nil), zap.Bool("with bearer", exec.prm.common.BearerToken() != nil), - ) + )} } func (exec execCtx) context() context.Context { diff --git a/pkg/services/object/search/service.go b/pkg/services/object/search/service.go index 231c19d9..76d0a3bf 100644 --- a/pkg/services/object/search/service.go +++ b/pkg/services/object/search/service.go @@ -55,7 +55,7 @@ type cfg struct { func defaultCfg() *cfg { return &cfg{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, clientConstructor: new(clientConstructorWrapper), } } @@ -77,7 +77,7 @@ func New(opts ...Option) *Service { // WithLogger returns option to specify Get service's logger. func WithLogger(l *logger.Logger) Option { return func(c *cfg) { - c.log = l.With(zap.String("component", "Object.Search service")) + c.log = &logger.Logger{Logger: l.With(zap.String("component", "Object.Search service"))} } } diff --git a/pkg/services/object_manager/tombstone/checker.go b/pkg/services/object_manager/tombstone/checker.go index 3046b3c2..96025405 100644 --- a/pkg/services/object_manager/tombstone/checker.go +++ b/pkg/services/object_manager/tombstone/checker.go @@ -6,6 +6,7 @@ import ( lru "github.com/hashicorp/golang-lru" objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" @@ -32,7 +33,7 @@ type Source interface { type ExpirationChecker struct { cache *lru.Cache - log *zap.Logger + log *logger.Logger tsSource Source } diff --git a/pkg/services/object_manager/tombstone/constructor.go b/pkg/services/object_manager/tombstone/constructor.go index 36f006c8..27ad10a7 100644 --- a/pkg/services/object_manager/tombstone/constructor.go +++ b/pkg/services/object_manager/tombstone/constructor.go @@ -4,13 +4,14 @@ import ( "fmt" lru "github.com/hashicorp/golang-lru" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap" ) const defaultLRUCacheSize = 100 type cfg struct { - log *zap.Logger + log *logger.Logger cacheSize int @@ -22,7 +23,7 @@ type Option func(*cfg) func defaultCfg() *cfg { return &cfg{ - log: zap.NewNop(), + log: &logger.Logger{Logger: zap.NewNop()}, cacheSize: defaultLRUCacheSize, } } @@ -61,7 +62,7 @@ func NewChecker(oo ...Option) *ExpirationChecker { // WithLogger returns an option to specify // logger. -func WithLogger(v *zap.Logger) Option { +func WithLogger(v *logger.Logger) Option { return func(c *cfg) { c.log = v } diff --git a/pkg/services/policer/policer.go b/pkg/services/policer/policer.go index 21807c32..ed0a2f8b 100644 --- a/pkg/services/policer/policer.go +++ b/pkg/services/policer/policer.go @@ -97,7 +97,7 @@ type cfg struct { func defaultCfg() *cfg { return &cfg{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, batchSize: 10, cacheSize: 200_000, // should not allocate more than 200 MiB rebalanceFreq: 1 * time.Second, @@ -113,7 +113,7 @@ func New(opts ...Option) *Policer { opts[i](c) } - c.log = c.log.With(zap.String("component", "Object Policer")) + c.log = &logger.Logger{Logger: c.log.With(zap.String("component", "Object Policer"))} cache, err := lru.New(int(c.cacheSize)) if err != nil { diff --git a/pkg/services/replicator/replicator.go b/pkg/services/replicator/replicator.go index 54cdb4bd..ee7bf887 100644 --- a/pkg/services/replicator/replicator.go +++ b/pkg/services/replicator/replicator.go @@ -40,7 +40,7 @@ func New(opts ...Option) *Replicator { opts[i](c) } - c.log = c.log.With(zap.String("component", "Object Replicator")) + c.log = &logger.Logger{Logger: c.log.With(zap.String("component", "Object Replicator"))} return &Replicator{ cfg: c, diff --git a/pkg/services/reputation/common/managers.go b/pkg/services/reputation/common/managers.go index 646ba6c1..4d31cd80 100644 --- a/pkg/services/reputation/common/managers.go +++ b/pkg/services/reputation/common/managers.go @@ -118,7 +118,7 @@ type MngOption func(*mngOptions) func defaultMngOpts() *mngOptions { return &mngOptions{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/services/reputation/common/router/opts.go b/pkg/services/reputation/common/router/opts.go index 20a3e2ee..a1d13d39 100644 --- a/pkg/services/reputation/common/router/opts.go +++ b/pkg/services/reputation/common/router/opts.go @@ -14,7 +14,7 @@ type options struct { func defaultOpts() *options { return &options{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/services/reputation/eigentrust/calculator/opts.go b/pkg/services/reputation/eigentrust/calculator/opts.go index 27577b03..bb13a2d4 100644 --- a/pkg/services/reputation/eigentrust/calculator/opts.go +++ b/pkg/services/reputation/eigentrust/calculator/opts.go @@ -14,7 +14,7 @@ type options struct { func defaultOpts() *options { return &options{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/services/reputation/eigentrust/controller/opts.go b/pkg/services/reputation/eigentrust/controller/opts.go index ef94c946..b1d62b66 100644 --- a/pkg/services/reputation/eigentrust/controller/opts.go +++ b/pkg/services/reputation/eigentrust/controller/opts.go @@ -14,7 +14,7 @@ type options struct { func defaultOpts() *options { return &options{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/services/reputation/local/controller/calls.go b/pkg/services/reputation/local/controller/calls.go index 5a73a49a..355a3dd4 100644 --- a/pkg/services/reputation/local/controller/calls.go +++ b/pkg/services/reputation/local/controller/calls.go @@ -75,9 +75,9 @@ func (c *Controller) acquireReport(epoch uint64) *reportContext { c.mtx.Unlock() - log := c.opts.log.With( + log := &logger.Logger{Logger: c.opts.log.With( zap.Uint64("epoch", epoch), - ) + )} if ctx == nil { log.Debug("report is already started") @@ -191,6 +191,6 @@ func (p *StopPrm) SetEpoch(e uint64) { func (c *Controller) Stop(prm StopPrm) { c.freeReport( prm.epoch, - c.opts.log.With(zap.Uint64("epoch", prm.epoch)), + &logger.Logger{Logger: c.opts.log.With(zap.Uint64("epoch", prm.epoch))}, ) } diff --git a/pkg/services/reputation/local/controller/opts.go b/pkg/services/reputation/local/controller/opts.go index 22d8bc34..0230344b 100644 --- a/pkg/services/reputation/local/controller/opts.go +++ b/pkg/services/reputation/local/controller/opts.go @@ -14,7 +14,7 @@ type options struct { func defaultOpts() *options { return &options{ - log: zap.L(), + log: &logger.Logger{Logger: zap.L()}, } } diff --git a/pkg/services/session/storage/persistent/options.go b/pkg/services/session/storage/persistent/options.go index 61a0969c..ee77b6ae 100644 --- a/pkg/services/session/storage/persistent/options.go +++ b/pkg/services/session/storage/persistent/options.go @@ -4,11 +4,12 @@ import ( "crypto/ecdsa" "time" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap" ) type cfg struct { - l *zap.Logger + l *logger.Logger timeout time.Duration privateKey *ecdsa.PrivateKey } @@ -18,14 +19,14 @@ type Option func(*cfg) func defaultCfg() *cfg { return &cfg{ - l: zap.L(), + l: &logger.Logger{Logger: zap.L()}, timeout: 100 * time.Millisecond, } } // WithLogger returns an option to specify // logger. -func WithLogger(v *zap.Logger) Option { +func WithLogger(v *logger.Logger) Option { return func(c *cfg) { c.l = v } diff --git a/pkg/services/session/storage/persistent/storage.go b/pkg/services/session/storage/persistent/storage.go index 4dd9fe82..62a5b86c 100644 --- a/pkg/services/session/storage/persistent/storage.go +++ b/pkg/services/session/storage/persistent/storage.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/user" "go.etcd.io/bbolt" "go.uber.org/zap" @@ -18,7 +19,7 @@ import ( type TokenStore struct { db *bbolt.DB - l *zap.Logger + l *logger.Logger // optional AES-256 algorithm // encryption in Galois/Counter diff --git a/pkg/services/tree/options.go b/pkg/services/tree/options.go index ef111b47..b3f01617 100644 --- a/pkg/services/tree/options.go +++ b/pkg/services/tree/options.go @@ -7,11 +7,11 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama" - "go.uber.org/zap" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" ) type cfg struct { - log *zap.Logger + log *logger.Logger key *ecdsa.PrivateKey rawPub []byte nmSource netmap.Source @@ -61,7 +61,7 @@ func WithPrivateKey(key *ecdsa.PrivateKey) Option { } // WithLogger sets logger for a tree service. -func WithLogger(log *zap.Logger) Option { +func WithLogger(log *logger.Logger) Option { return func(c *cfg) { c.log = log } diff --git a/pkg/services/tree/service.go b/pkg/services/tree/service.go index aca6b961..03d6673b 100644 --- a/pkg/services/tree/service.go +++ b/pkg/services/tree/service.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/container/acl" cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id" netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap" @@ -39,7 +40,7 @@ func New(opts ...Option) *Service { } if s.log == nil { - s.log = zap.NewNop() + s.log = &logger.Logger{Logger: zap.NewNop()} } s.cache.init() diff --git a/pkg/services/tree/signature_test.go b/pkg/services/tree/signature_test.go index 990e20a6..4cdc2d73 100644 --- a/pkg/services/tree/signature_test.go +++ b/pkg/services/tree/signature_test.go @@ -10,6 +10,7 @@ import ( aclV2 "github.com/nspcc-dev/neofs-api-go/v2/acl" containercore "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/bearer" "github.com/nspcc-dev/neofs-sdk-go/container" "github.com/nspcc-dev/neofs-sdk-go/container/acl" @@ -70,7 +71,7 @@ func TestMessageSign(t *testing.T) { s := &Service{ cfg: cfg{ - log: zaptest.NewLogger(t), + log: &logger.Logger{Logger: zaptest.NewLogger(t)}, key: &privs[0].PrivateKey, nmSource: dummyNetmapSource{}, cnrSource: dummyContainerSource{ diff --git a/pkg/util/logger/logger.go b/pkg/util/logger/logger.go index 365b42bd..e6afb58d 100644 --- a/pkg/util/logger/logger.go +++ b/pkg/util/logger/logger.go @@ -9,10 +9,10 @@ import ( // Logger represents a component // for writing messages to log. -// -// It is a type alias of -// go.uber.org/zap.Logger. -type Logger = zap.Logger +type Logger struct { + *zap.Logger + lvl zap.AtomicLevel +} // Prm groups Logger's parameters. type Prm struct { @@ -40,12 +40,19 @@ func (p *Prm) SetLevelString(s string) error { // // Logger records a stack trace for all messages at or above fatal level. func NewLogger(prm Prm) (*Logger, error) { + lvl := zap.NewAtomicLevelAt(prm.level) + c := zap.NewProductionConfig() - c.Level = zap.NewAtomicLevelAt(prm.level) + c.Level = lvl c.Encoding = "console" c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder - return c.Build( + l, err := c.Build( zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)), ) + if err != nil { + return nil, err + } + + return &Logger{Logger: l, lvl: lvl}, nil } diff --git a/pkg/util/logger/test/logger.go b/pkg/util/logger/test/logger.go index d2dda19d..92d10448 100644 --- a/pkg/util/logger/test/logger.go +++ b/pkg/util/logger/test/logger.go @@ -12,6 +12,9 @@ const sampling = 1000 // // If debug, development logger is created. func NewLogger(debug bool) *logger.Logger { + var l logger.Logger + l.Logger = zap.L() + if debug { cfg := zap.NewDevelopmentConfig() cfg.Sampling = &zap.SamplingConfig{ @@ -26,8 +29,8 @@ func NewLogger(debug bool) *logger.Logger { panic("could not prepare logger: " + err.Error()) } - return log + l.Logger = log } - return zap.L() + return &l }