diff options
author | max42 <max42@yandex-team.com> | 2023-07-29 00:02:16 +0300 |
---|---|---|
committer | max42 <max42@yandex-team.com> | 2023-07-29 00:02:16 +0300 |
commit | 73b89de71748a21e102d27b9f3ed1bf658766cb5 (patch) | |
tree | 188bbd2d622fa91cdcbb1b6d6d77fbc84a0646f5 /yt/cpp/mapreduce/interface/logging/yt_log.cpp | |
parent | 528e321bcc2a2b67b53aeba58c3bd88305a141ee (diff) | |
download | ydb-73b89de71748a21e102d27b9f3ed1bf658766cb5.tar.gz |
YT-19210: expose YQL shared library for YT.
After this, a new target libyqlplugin.so appears. in open-source cmake build.
Diff in open-source YDB repo looks like the following: https://paste.yandex-team.ru/f302bdb4-7ef2-4362-91c7-6ca45f329264
Diffstat (limited to 'yt/cpp/mapreduce/interface/logging/yt_log.cpp')
-rw-r--r-- | yt/cpp/mapreduce/interface/logging/yt_log.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/yt/cpp/mapreduce/interface/logging/yt_log.cpp b/yt/cpp/mapreduce/interface/logging/yt_log.cpp new file mode 100644 index 0000000000..9fa7b91580 --- /dev/null +++ b/yt/cpp/mapreduce/interface/logging/yt_log.cpp @@ -0,0 +1,126 @@ +#include "yt_log.h" + +#include "logger.h" + +#include <util/generic/guid.h> + +#include <util/system/mutex.h> + +namespace NYT { + +using namespace NLogging; + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +class TLogManager + : public ILogManager +{ +public: + static constexpr TStringBuf CategoryName = "Wrapper"; + +public: + void RegisterStaticAnchor( + TLoggingAnchor* anchor, + ::TSourceLocation sourceLocation, + TStringBuf anchorMessage) override + { + if (anchor->Registered.exchange(true)) { + return; + } + + anchor->Enabled.store(true); + + auto guard = Guard(Mutex_); + anchor->SourceLocation = sourceLocation; + anchor->AnchorMessage = anchorMessage; + } + + void UpdateAnchor(TLoggingAnchor* /*position*/) override + { } + + void Enqueue(TLogEvent&& event) override + { + auto message = TString(event.MessageRef.ToStringBuf()); + LogMessage( + ToImplLevel(event.Level), + ::TSourceLocation(event.SourceFile, event.SourceLine), + "%.*s", + event.MessageRef.size(), + event.MessageRef.begin()); + } + + const TLoggingCategory* GetCategory(TStringBuf categoryName) override + { + Y_VERIFY(categoryName == CategoryName); + return &Category_; + } + + void UpdateCategory(TLoggingCategory* /*category*/) override + { + Y_FAIL(); + } + + bool GetAbortOnAlert() const override + { + return false; + } + +private: + static ILogger::ELevel ToImplLevel(ELogLevel level) + { + switch (level) { + case ELogLevel::Minimum: + case ELogLevel::Trace: + case ELogLevel::Debug: + return ILogger::ELevel::DEBUG; + case ELogLevel::Info: + return ILogger::ELevel::INFO; + case ELogLevel::Warning: + case ELogLevel::Error: + return ILogger::ELevel::ERROR; + case ELogLevel::Alert: + case ELogLevel::Fatal: + case ELogLevel::Maximum: + return ILogger::ELevel::FATAL; + } + } + + static void LogMessage(ILogger::ELevel level, const ::TSourceLocation& sourceLocation, const char* format, ...) + { + va_list args; + va_start(args, format); + GetLogger()->Log(level, sourceLocation, format, args); + va_end(args); + } + +private: + ::TMutex Mutex_; + std::atomic<int> ActualVersion_{1}; + const TLoggingCategory Category_{ + .Name{CategoryName}, + .MinPlainTextLevel{ELogLevel::Minimum}, + .CurrentVersion{1}, + .ActualVersion = &ActualVersion_, + }; +}; + +TLogManager LogManager; + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// + +TLogger Logger(&LogManager, TLogManager::CategoryName); + +//////////////////////////////////////////////////////////////////////////////// + +void FormatValue(TStringBuilderBase* builder, const TGUID& value, TStringBuf /*format*/) +{ + builder->AppendString(GetGuidAsString(value)); +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT |