diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/logger/global/common.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/logger/global/common.cpp')
-rw-r--r-- | library/cpp/logger/global/common.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/library/cpp/logger/global/common.cpp b/library/cpp/logger/global/common.cpp new file mode 100644 index 0000000000..4fb05c19b4 --- /dev/null +++ b/library/cpp/logger/global/common.cpp @@ -0,0 +1,36 @@ +#include "common.h" + +#include <util/generic/yexception.h> + +namespace NLoggingImpl { + TString GetLocalTimeSSimple() { + struct tm tm; + return Strftime("%b%d_%H%M%S", Now().LocalTime(&tm)); + } + + TString PrepareToOpenLog(TString logType, const int logLevel, const bool rotation, const bool startAsDaemon) { + Y_ENSURE(logLevel >= 0 && logLevel <= (int)LOG_MAX_PRIORITY, "Incorrect log level"); + + if (rotation && TFsPath(logType).Exists()) { + TString newPath = Sprintf("%s_%s_%" PRIu64, logType.data(), NLoggingImpl::GetLocalTimeSSimple().data(), static_cast<ui64>(Now().MicroSeconds())); + TFsPath(logType).RenameTo(newPath); + } + if (startAsDaemon && (logType == "console"sv || logType == "cout"sv || logType == "cerr"sv)) { + logType = "null"; + } + + return logType; + } +} + +bool TLogFilter::CheckLoggingContext(TLog& log, const TLogRecordContext& context) { + return context.Priority <= log.FiltrationLevel(); +} + +TSimpleSharedPtr<TLogElement> TLogFilter::StartRecord(TLog& logger, const TLogRecordContext& context, TSimpleSharedPtr<TLogElement> earlier) { + if (earlier) + return earlier; + TSimpleSharedPtr<TLogElement> result(new TLogElement(&logger)); + *result << context.Priority; + return result; +} |