From 0a53819a4fa41d22e878c4cd3c4d95330f583deb Mon Sep 17 00:00:00 2001 From: hiddenpath Date: Sat, 3 May 2025 01:51:57 +0300 Subject: YT-24500: Introduce structured logging commit_hash:e6ea4db1e3a66694223008fec3b5064a4d58a8e1 --- yt/cpp/mapreduce/interface/logging/structured.cpp | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 yt/cpp/mapreduce/interface/logging/structured.cpp (limited to 'yt/cpp/mapreduce/interface/logging/structured.cpp') 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 +#include + +#include + +namespace NYT::NDetail { + +using namespace NLogging; + +//////////////////////////////////////////////////////////////////////////////// + +void InitializeStructuredLogging( + TLogManagerConfigPtr logManagerConfig, + const TString& structuredLogPath) +{ + auto ruleConfig = New(); + ruleConfig->MinLevel = ELogLevel::Info; + ruleConfig->Writers.push_back(StructuredLogTypeName); + ruleConfig->IncludeCategories = {"Structured"}; + + auto writerConfig = New(); + writerConfig->Type = StructuredLogTypeName; + writerConfig->FileName = NFS::NormalizePathSeparators(structuredLogPath); + writerConfig->Format = ELogFormat::Json; + + logManagerConfig->Rules.emplace_back(std::move(ruleConfig)); + + EmplaceOrCrash( + logManagerConfig->Writers, + StructuredLogTypeName, + ConvertTo(writerConfig)); +} + +void RegisterStructuredLogWriterFactory() +{ + TLogManager::Get()->RegisterWriterFactory(StructuredLogTypeName, GetFileLogWriterFactory()); +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT::NDetail -- cgit v1.3