/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
library/cpp/logger/global/common.cpp
36 строк
1 KB
qkrorlqr
Initial NBS OpenSource export
28 апр 2023, 21:54
28 апр 2023, 21:54
783a858
Код
Авторство
О чём код?
#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; }