diff options
author | m-milkin <m-milkin@yandex-team.com> | 2023-04-14 15:40:27 +0300 |
---|---|---|
committer | m-milkin <m-milkin@yandex-team.com> | 2023-04-14 15:40:27 +0300 |
commit | fb642d882910bcf70b25fa17c3de522e61b4ac84 (patch) | |
tree | 5eb54fe4209510f211280aaaba63ede17ad1e2ea /library/cpp/logger/element.h | |
parent | 8c60d32628e9e0c4659bd837a357b08973070031 (diff) | |
download | ydb-fb642d882910bcf70b25fa17c3de522e61b4ac84.tar.gz |
[library/cpp/logger] Support meta flags with TLogElement
Support opportunity to use TMetaFlags with TLogElement.
**Use example:**
`Log().With("Property", "Value").With("Code", "Code") << LogMessage`
Such interface allows to not parse required by TLogBackend properties from raw string.
Diffstat (limited to 'library/cpp/logger/element.h')
-rw-r--r-- | library/cpp/logger/element.h | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/library/cpp/logger/element.h b/library/cpp/logger/element.h index fc9bff851f..9ba27ab67e 100644 --- a/library/cpp/logger/element.h +++ b/library/cpp/logger/element.h @@ -1,18 +1,20 @@ #pragma once #include "priority.h" +#include "record.h" + +#include <util/string/cast.h> #include <util/stream/tempbuf.h> + class TLog; -/* - * better do not use directly - */ +/// @warning Better don't use directly. class TLogElement: public TTempBufOutput { public: - TLogElement(const TLog* parent); - TLogElement(const TLog* parent, ELogPriority priority); + explicit TLogElement(const TLog* parent); + explicit TLogElement(const TLog* parent, ELogPriority priority); TLogElement(TLogElement&&) noexcept = default; TLogElement& operator=(TLogElement&&) noexcept = default; @@ -26,15 +28,20 @@ public: return *this; } - /* - * for pretty usage: logger << TLOG_ERROR << "Error description"; - */ + /// @note For pretty usage: logger << TLOG_ERROR << "Error description"; inline TLogElement& operator<<(ELogPriority priority) { Flush(); Priority_ = priority; return *this; } + template<typename T> + TLogElement& With(const TStringBuf key, const T value) { + Context_.emplace_back(key, ToString(value)); + + return *this; + } + ELogPriority Priority() const noexcept { return Priority_; } @@ -43,6 +50,7 @@ protected: void DoFlush() override; protected: - const TLog* Parent_; + const TLog* Parent_ = nullptr; ELogPriority Priority_; + TLogRecord::TMetaFlags Context_; }; |