aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp
diff options
context:
space:
mode:
authorermolovd <ermolovd@yandex-team.com>2024-11-28 15:34:32 +0300
committerermolovd <ermolovd@yandex-team.com>2024-11-28 15:45:53 +0300
commit667d7a8073070f148e1adc7650b55e7a7ef33439 (patch)
treee03282783ef7606d02176e91114582bbc8f5dd13 /yt/cpp
parent4ba1f3d99a3e5499a3a0fa5c22a4628fe41f06f4 (diff)
downloadydb-667d7a8073070f148e1adc7650b55e7a7ef33439.tar.gz
YT-23645: mapreduce client can use yt/core log manager
commit_hash:7007a3c7f56a6f271073811160f00f03162aaaa6
Diffstat (limited to 'yt/cpp')
-rw-r--r--yt/cpp/mapreduce/client/init.cpp22
-rw-r--r--yt/cpp/mapreduce/interface/config.cpp1
-rw-r--r--yt/cpp/mapreduce/interface/config.h12
-rw-r--r--yt/cpp/mapreduce/interface/logging/logger.cpp7
-rw-r--r--yt/cpp/mapreduce/interface/logging/logger.h4
-rw-r--r--yt/cpp/mapreduce/interface/logging/yt_log.cpp31
6 files changed, 57 insertions, 20 deletions
diff --git a/yt/cpp/mapreduce/client/init.cpp b/yt/cpp/mapreduce/client/init.cpp
index 242bbcb2bb..6121952f86 100644
--- a/yt/cpp/mapreduce/client/init.cpp
+++ b/yt/cpp/mapreduce/client/init.cpp
@@ -166,27 +166,32 @@ NLogging::ELogLevel ToCoreLogLevel(ILogger::ELevel level)
Y_ABORT();
}
-void CommonInitialize(int, const char**)
+void CommonInitialize(TGuard<TMutex>& g)
{
auto logLevelStr = to_lower(TConfig::Get()->LogLevel);
ILogger::ELevel logLevel;
if (!TryFromString(logLevelStr, logLevel)) {
Cerr << "Invalid log level: " << TConfig::Get()->LogLevel << Endl;
+ g.Release();
exit(1);
}
auto logPath = TConfig::Get()->LogPath;
- ILoggerPtr logger;
if (logPath.empty()) {
- logger = CreateStdErrLogger(logLevel);
+ if (TConfig::Get()->LogUseCore) {
+ auto coreLoggingConfig = NLogging::TLogManagerConfig::CreateStderrLogger(ToCoreLogLevel(logLevel));
+ NLogging::TLogManager::Get()->Configure(coreLoggingConfig);
+ SetUseCoreLog();
+ } else {
+ auto logger = CreateStdErrLogger(logLevel);
+ SetLogger(logger);
+ }
} else {
- logger = CreateFileLogger(logLevel, logPath, /*append*/ true);
-
auto coreLoggingConfig = NLogging::TLogManagerConfig::CreateLogFile(logPath, ToCoreLogLevel(logLevel));
NLogging::TLogManager::Get()->Configure(coreLoggingConfig);
+ SetUseCoreLog();
}
- SetLogger(logger);
}
void NonJobInitialize(const TInitializeOptions& options)
@@ -281,8 +286,7 @@ void JoblessInitialize(const TInitializeOptions& options)
{
auto g = Guard(InitializeLock);
- static const char* fakeArgv[] = {"unknown..."};
- NDetail::CommonInitialize(1, fakeArgv);
+ NDetail::CommonInitialize(g);
NDetail::NonJobInitialize(options);
NDetail::ElevateInitStatus(NDetail::EInitStatus::JoblessInitialization);
}
@@ -291,7 +295,7 @@ void Initialize(int argc, const char* argv[], const TInitializeOptions& options)
{
auto g = Guard(InitializeLock);
- NDetail::CommonInitialize(argc, argv);
+ NDetail::CommonInitialize(g);
NDetail::ElevateInitStatus(NDetail::EInitStatus::FullInitialization);
diff --git a/yt/cpp/mapreduce/interface/config.cpp b/yt/cpp/mapreduce/interface/config.cpp
index b1f546f7a4..0ed5cb57f8 100644
--- a/yt/cpp/mapreduce/interface/config.cpp
+++ b/yt/cpp/mapreduce/interface/config.cpp
@@ -194,6 +194,7 @@ void TConfig::Reset()
ApiVersion = GetEnv("YT_VERSION", "v3");
LogLevel = GetEnv("YT_LOG_LEVEL", "error");
LogPath = GetEnv("YT_LOG_PATH");
+ LogUseCore = GetBool("YT_LOG_USE_CORE", false);
ContentEncoding = GetEncoding("YT_CONTENT_ENCODING");
AcceptEncoding = GetEncoding("YT_ACCEPT_ENCODING");
diff --git a/yt/cpp/mapreduce/interface/config.h b/yt/cpp/mapreduce/interface/config.h
index 05c4c473e5..4d1fd49e8c 100644
--- a/yt/cpp/mapreduce/interface/config.h
+++ b/yt/cpp/mapreduce/interface/config.h
@@ -81,6 +81,18 @@ struct TConfig
TString LogLevel;
TString LogPath;
+ ///
+ /// For historical reasons mapreduce client uses its own logging system.
+ ///
+ /// If this options is set to true library switches to yt/yt/core logging by default.
+ /// But if user calls @ref NYT::SetLogger library switches back to logger provided by user
+ /// (except for messages from yt/yt/core).
+ ///
+ /// This is temporary option. In future it would be true by default, and then removed.
+ ///
+ /// https://st.yandex-team.ru/YT-23645
+ bool LogUseCore = false;
+
// Compression for data that is sent to YT cluster.
EEncoding ContentEncoding;
diff --git a/yt/cpp/mapreduce/interface/logging/logger.cpp b/yt/cpp/mapreduce/interface/logging/logger.cpp
index bfa56b94f6..5878c960ff 100644
--- a/yt/cpp/mapreduce/interface/logging/logger.cpp
+++ b/yt/cpp/mapreduce/interface/logging/logger.cpp
@@ -182,7 +182,12 @@ ILoggerPtr GetLogger()
return Logger;
}
+void SetUseCoreLog()
+{
+ auto guard = TWriteGuard(LoggerMutex);
+ Logger = nullptr;
+}
+
////////////////////////////////////////////////////////////////////////////////
}
-
diff --git a/yt/cpp/mapreduce/interface/logging/logger.h b/yt/cpp/mapreduce/interface/logging/logger.h
index 2b5aae87d1..780327961d 100644
--- a/yt/cpp/mapreduce/interface/logging/logger.h
+++ b/yt/cpp/mapreduce/interface/logging/logger.h
@@ -30,6 +30,8 @@ using ILoggerPtr = ::TIntrusivePtr<ILogger>;
void SetLogger(ILoggerPtr logger);
ILoggerPtr GetLogger();
+void SetUseCoreLog();
+
ILoggerPtr CreateStdErrLogger(ILogger::ELevel cutLevel);
ILoggerPtr CreateFileLogger(ILogger::ELevel cutLevel, const TString& path, bool append = false);
@@ -40,4 +42,6 @@ ILoggerPtr CreateFileLogger(ILogger::ELevel cutLevel, const TString& path, bool
*/
ILoggerPtr CreateBufferedFileLogger(ILogger::ELevel cutLevel, const TString& path, bool append = false);
+////////////////////////////////////////////////////////////////////////////////
+
} // namespace NYT
diff --git a/yt/cpp/mapreduce/interface/logging/yt_log.cpp b/yt/cpp/mapreduce/interface/logging/yt_log.cpp
index d41bfa559f..6c464d48ac 100644
--- a/yt/cpp/mapreduce/interface/logging/yt_log.cpp
+++ b/yt/cpp/mapreduce/interface/logging/yt_log.cpp
@@ -26,23 +26,34 @@ public:
::TSourceLocation sourceLocation,
TStringBuf anchorMessage) override
{
+ if (auto* defaultLogManager = GetDefaultLogManager()) {
+ defaultLogManager->RegisterStaticAnchor(anchor, sourceLocation, anchorMessage);
+ }
auto guard = Guard(Mutex_);
anchor->SourceLocation = sourceLocation;
anchor->AnchorMessage = anchorMessage;
}
- void UpdateAnchor(TLoggingAnchor* /*position*/) override
- { }
+ void UpdateAnchor(TLoggingAnchor* anchor) override
+ {
+ if (auto* defaultLogManager = GetDefaultLogManager()) {
+ defaultLogManager->UpdateAnchor(anchor);
+ }
+ }
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());
+ if (auto logger = GetLogger()) {
+ LogMessage(
+ logger,
+ ToImplLevel(event.Level),
+ ::TSourceLocation(event.SourceFile, event.SourceLine),
+ "%.*s",
+ event.MessageRef.size(),
+ event.MessageRef.begin());
+ } else if (auto* defaultLogManager = GetDefaultLogManager()) {
+ defaultLogManager->Enqueue(std::move(event));
+ }
}
const TLoggingCategory* GetCategory(TStringBuf categoryName) override
@@ -81,7 +92,7 @@ private:
}
}
- static void LogMessage(ILogger::ELevel level, const ::TSourceLocation& sourceLocation, const char* format, ...)
+ static void LogMessage(const ILoggerPtr& logger, ILogger::ELevel level, const ::TSourceLocation& sourceLocation, const char* format, ...)
{
va_list args;
va_start(args, format);