summaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/interface/logging/structured.cpp
diff options
context:
space:
mode:
authorhiddenpath <[email protected]>2025-05-03 01:51:57 +0300
committerhiddenpath <[email protected]>2025-05-03 02:02:40 +0300
commit0a53819a4fa41d22e878c4cd3c4d95330f583deb (patch)
tree33851f3ef8ddc4966b4539946e254cf1f400d779 /yt/cpp/mapreduce/interface/logging/structured.cpp
parentacb2861c75522a1fb9ccfaf8fec3ed71aca4a685 (diff)
YT-24500: Introduce structured logging
commit_hash:e6ea4db1e3a66694223008fec3b5064a4d58a8e1
Diffstat (limited to 'yt/cpp/mapreduce/interface/logging/structured.cpp')
-rw-r--r--yt/cpp/mapreduce/interface/logging/structured.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/yt/cpp/mapreduce/interface/logging/structured.cpp b/yt/cpp/mapreduce/interface/logging/structured.cpp
new file mode 100644
index 00000000000..ab5a4f2626f
--- /dev/null
+++ b/yt/cpp/mapreduce/interface/logging/structured.cpp
@@ -0,0 +1,43 @@
+#include "structured.h"
+
+#include <yt/yt/core/logging/config.h>
+#include <yt/yt/core/logging/file_log_writer.h>
+
+#include <yt/yt/core/misc/fs.h>
+
+namespace NYT::NDetail {
+
+using namespace NLogging;
+
+////////////////////////////////////////////////////////////////////////////////
+
+void InitializeStructuredLogging(
+ TLogManagerConfigPtr logManagerConfig,
+ const TString& structuredLogPath)
+{
+ auto ruleConfig = New<TRuleConfig>();
+ ruleConfig->MinLevel = ELogLevel::Info;
+ ruleConfig->Writers.push_back(StructuredLogTypeName);
+ ruleConfig->IncludeCategories = {"Structured"};
+
+ auto writerConfig = New<TFileLogWriterConfig>();
+ writerConfig->Type = StructuredLogTypeName;
+ writerConfig->FileName = NFS::NormalizePathSeparators(structuredLogPath);
+ writerConfig->Format = ELogFormat::Json;
+
+ logManagerConfig->Rules.emplace_back(std::move(ruleConfig));
+
+ EmplaceOrCrash(
+ logManagerConfig->Writers,
+ StructuredLogTypeName,
+ ConvertTo<NYTree::IMapNodePtr>(writerConfig));
+}
+
+void RegisterStructuredLogWriterFactory()
+{
+ TLogManager::Get()->RegisterWriterFactory(StructuredLogTypeName, GetFileLogWriterFactory());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT::NDetail