aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-05-27 19:50:46 +0300
committerarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-05-27 19:50:46 +0300
commitead94f115cf55ab55ce53ce3a2843ce63f21f65e (patch)
tree69b7fecf9f1bea5d821384e43b16b722b4c1db25
parent7a726dd33a56a13def3a2a408db847290055e991 (diff)
downloadydb-ead94f115cf55ab55ce53ce3a2843ce63f21f65e.tar.gz
intermediate changes
ref:86feec6f48cc49e43122519f168309a6a8bb2cba
-rw-r--r--build/ya.conf.json2
-rw-r--r--library/cpp/logger/log.cpp18
-rw-r--r--library/cpp/logger/log.h7
-rw-r--r--library/cpp/logger/log_ut.cpp29
-rw-r--r--library/cpp/logger/record.h10
5 files changed, 52 insertions, 14 deletions
diff --git a/build/ya.conf.json b/build/ya.conf.json
index 049ad972f5..7d07476a9c 100644
--- a/build/ya.conf.json
+++ b/build/ya.conf.json
@@ -7593,7 +7593,7 @@
"formula": {
"sandbox_id": [
1294905624,
- 1318308136
+ 1322364102
],
"match": "GDB"
},
diff --git a/library/cpp/logger/log.cpp b/library/cpp/logger/log.cpp
index e1d70cc3d2..6c4a898ab2 100644
--- a/library/cpp/logger/log.cpp
+++ b/library/cpp/logger/log.cpp
@@ -98,9 +98,9 @@ public:
Y_ASSERT(!IsOpen());
}
- inline void WriteData(ELogPriority priority, const char* data, size_t len) const {
+ inline void WriteData(ELogPriority priority, const char* data, size_t len, TLogRecord::TMetaFlags metaFlags = {}) const {
if (IsOpen()) {
- Backend_->WriteData(TLogRecord(priority, data, len));
+ Backend_->WriteData(TLogRecord(priority, data, len, std::move(metaFlags)));
}
}
@@ -226,21 +226,21 @@ THolder<TLogBackend> TLog::ReleaseBackend() noexcept {
return Impl_->ReleaseBackend();
}
-void TLog::Write(ELogPriority priority, const char* data, size_t len) const {
+void TLog::Write(ELogPriority priority, const char* data, size_t len, TLogRecord::TMetaFlags metaFlags) const {
if (Formatter_) {
const auto formated = Formatter_(priority, TStringBuf{data, len});
- Impl_->WriteData(priority, formated.data(), formated.size());
+ Impl_->WriteData(priority, formated.data(), formated.size(), std::move(metaFlags));
} else {
- Impl_->WriteData(priority, data, len);
+ Impl_->WriteData(priority, data, len, std::move(metaFlags));
}
}
-void TLog::Write(ELogPriority priority, const TStringBuf data) const {
- Write(priority, data.data(), data.size());
+void TLog::Write(ELogPriority priority, const TStringBuf data, TLogRecord::TMetaFlags metaFlags) const {
+ Write(priority, data.data(), data.size(), std::move(metaFlags));
}
-void TLog::Write(const char* data, size_t len) const {
- Write(Impl_->DefaultPriority(), data, len);
+void TLog::Write(const char* data, size_t len, TLogRecord::TMetaFlags metaFlags) const {
+ Write(Impl_->DefaultPriority(), data, len, std::move(metaFlags));
}
void TLog::SetFormatter(TLogFormatter formatter) noexcept {
diff --git a/library/cpp/logger/log.h b/library/cpp/logger/log.h
index 8be984ccc8..7520cc1530 100644
--- a/library/cpp/logger/log.h
+++ b/library/cpp/logger/log.h
@@ -59,11 +59,12 @@ public:
//
// @param[in] priority Message priority to use.
// @param[in] message Message to write.
- void Write(ELogPriority priority, TStringBuf message) const;
+ // @param[in] metaFlags Message meta flags.
+ void Write(ELogPriority priority, TStringBuf message, TLogRecord::TMetaFlags metaFlags = {}) const;
// Write message to the log using `DefaultPriority()`.
- void Write(const char* data, size_t len) const;
+ void Write(const char* data, size_t len, TLogRecord::TMetaFlags metaFlags = {}) const;
// Write message to the log, but pass the message in a c-style.
- void Write(ELogPriority priority, const char* data, size_t len) const;
+ void Write(ELogPriority priority, const char* data, size_t len, TLogRecord::TMetaFlags metaFlags = {}) const;
// Write message to the log in a c-like printf style.
void Y_PRINTF_FORMAT(3, 4) AddLog(ELogPriority priority, const char* format, ...) const;
diff --git a/library/cpp/logger/log_ut.cpp b/library/cpp/logger/log_ut.cpp
index 8de46f17f5..747e5dddf8 100644
--- a/library/cpp/logger/log_ut.cpp
+++ b/library/cpp/logger/log_ut.cpp
@@ -18,6 +18,7 @@ class TLogTest: public TTestBase {
UNIT_TEST(TestThreaded)
UNIT_TEST(TestThreadedWithOverflow)
UNIT_TEST(TestNoFlush)
+ UNIT_TEST(TestMetaFlags)
UNIT_TEST_SUITE_END();
private:
@@ -27,6 +28,7 @@ private:
void TestThreaded();
void TestThreadedWithOverflow();
void TestNoFlush();
+ void TestMetaFlags();
void SetUp() override;
void TearDown() override;
};
@@ -182,6 +184,33 @@ void TLogTest::TestWrite() {
UNIT_ASSERT_EQUAL(data.Str(), test);
}
+void TLogTest::TestMetaFlags() {
+ class TTestLogBackendStub: public TLogBackend {
+ public:
+ TTestLogBackendStub(TLogRecord::TMetaFlags& data)
+ : Data_(data)
+ {
+ }
+
+ void WriteData(const TLogRecord& record) override {
+ Data_ = record.MetaFlags;
+ }
+
+ void ReopenLog() override {
+ }
+
+ private:
+ TLogRecord::TMetaFlags& Data_;
+ };
+
+ TLogRecord::TMetaFlags metaFlags;
+ TLog log(MakeHolder<TTestLogBackendStub>(metaFlags));
+ log.Write(ELogPriority::TLOG_INFO, TString("message"), {{"key", "value"}});
+
+ TLogRecord::TMetaFlags expected{{"key", "value"}};
+ UNIT_ASSERT_EQUAL(metaFlags, expected);
+}
+
void TLogTest::SetUp() {
TearDown();
}
diff --git a/library/cpp/logger/record.h b/library/cpp/logger/record.h
index c28a7785fd..9c2062c3ee 100644
--- a/library/cpp/logger/record.h
+++ b/library/cpp/logger/record.h
@@ -2,17 +2,25 @@
#include "priority.h"
+#include <util/generic/string.h>
+#include <util/generic/vector.h>
#include <util/system/defaults.h>
+#include <utility>
+
struct TLogRecord {
+ using TMetaFlags = TVector<std::pair<TString, TString>>;
+
const char* Data;
size_t Len;
ELogPriority Priority;
+ TMetaFlags MetaFlags;
- inline TLogRecord(ELogPriority priority, const char* data, size_t len) noexcept
+ inline TLogRecord(ELogPriority priority, const char* data, size_t len, TMetaFlags metaFlags = {}) noexcept
: Data(data)
, Len(len)
, Priority(priority)
+ , MetaFlags(std::move(metaFlags))
{
}
};