From 3cfb58aabd388ebc08b1b7f3ab115ed653e1f70d Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 6 Sep 2021 17:25:27 +0300 Subject: [PATCH] [#790] storage engine: Add common template of log messages There is a need to keep track of each local storage change. Log messages are the most convenient way to do it. Implement function which writes log message about the completed writing operation in storage engine. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/internal/log/log.go | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 pkg/local_object_storage/internal/log/log.go diff --git a/pkg/local_object_storage/internal/log/log.go b/pkg/local_object_storage/internal/log/log.go new file mode 100644 index 000000000..5cf010000 --- /dev/null +++ b/pkg/local_object_storage/internal/log/log.go @@ -0,0 +1,26 @@ +package storagelog + +import ( + "github.com/nspcc-dev/neofs-node/pkg/util/logger" + "go.uber.org/zap" +) + +// a distinctive part of all messages +const headMsg = "local object storage operation" + +// Write writes message about storage engine's operation to logger. +func Write(logger *logger.Logger, fields ...zap.Field) { + logger.Info(headMsg, fields...) +} + +// AddressField returns logger's field for object address. +// +// Address should be type of *object.Address or string. +func AddressField(addr interface{}) zap.Field { + return zap.Any("address", addr) +} + +// AddressField returns logger's field for operation type. +func OpField(op string) zap.Field { + return zap.String("op", op) +}