diff options
author | iddqd <iddqd@yandex-team.ru> | 2022-02-10 16:49:45 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:45 +0300 |
commit | 07fce9c5f7771600d0b3d70e1f88fd8a7e164d85 (patch) | |
tree | e4aa4750fbb864d70f8c06cf03d2750e979ea3bf /library/cpp/logger/global/common.h | |
parent | af42068bf6cd93c976b80dd0388fa48cdf65da11 (diff) | |
download | ydb-07fce9c5f7771600d0b3d70e1f88fd8a7e164d85.tar.gz |
Restoring authorship annotation for <iddqd@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/logger/global/common.h')
-rw-r--r-- | library/cpp/logger/global/common.h | 142 |
1 files changed, 71 insertions, 71 deletions
diff --git a/library/cpp/logger/global/common.h b/library/cpp/logger/global/common.h index 7dcf650dec..a7a422c786 100644 --- a/library/cpp/logger/global/common.h +++ b/library/cpp/logger/global/common.h @@ -1,26 +1,26 @@ -#pragma once - -#include <util/datetime/base.h> - -#include <util/folder/path.h> -#include <util/generic/singleton.h> +#pragma once + +#include <util/datetime/base.h> + +#include <util/folder/path.h> +#include <util/generic/singleton.h> #include <util/generic/string.h> -#include <util/generic/ptr.h> -#include <util/generic/yexception.h> -#include <util/string/printf.h> -#include <util/system/src_location.h> - +#include <util/generic/ptr.h> +#include <util/generic/yexception.h> +#include <util/string/printf.h> +#include <util/system/src_location.h> + #include <library/cpp/logger/log.h> - + namespace NLoggingImpl { const size_t SingletonPriority = 500; } -template <class T> -T* CreateDefaultLogger() { - return nullptr; -} - +template <class T> +T* CreateDefaultLogger() { + return nullptr; +} + namespace NLoggingImpl { template<class T, class TTraits> class TOperatorBase { @@ -37,7 +37,7 @@ namespace NLoggingImpl { inline static bool Usage() { return SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Get(); } - + inline static T* Get() { return SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Get(); } @@ -45,8 +45,8 @@ namespace NLoggingImpl { inline static void Set(T* v) { SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Reset(v); } - }; - + }; + template<class T> struct TLoggerTraits { static T* CreateDefault() { @@ -54,20 +54,20 @@ namespace NLoggingImpl { } }; } - + template <class T> class TLoggerOperator : public NLoggingImpl::TOperatorBase<T, NLoggingImpl::TLoggerTraits<T>> { public: - inline static TLog& Log() { + inline static TLog& Log() { Y_ASSERT(TLoggerOperator::Usage()); return *TLoggerOperator::Get(); - } + } }; -namespace NLoggingImpl { - +namespace NLoggingImpl { + TString GetLocalTimeSSimple(); - + // Returns correct log type to use TString PrepareToOpenLog(TString logType, int logLevel, bool rotation, bool startAsDaemon); @@ -75,64 +75,64 @@ namespace NLoggingImpl { void InitLogImpl(TString logType, const int logLevel, const bool rotation, const bool startAsDaemon) { TLoggerOperator<TLoggerType>::Set(new TLoggerType(PrepareToOpenLog(logType, logLevel, rotation, startAsDaemon), (ELogPriority)logLevel)); } -} - -struct TLogRecordContext { +} + +struct TLogRecordContext { constexpr TLogRecordContext(const TSourceLocation& sourceLocation, TStringBuf customMessage, ELogPriority priority) : SourceLocation(sourceLocation) , CustomMessage(customMessage) , Priority(priority) {} - - TSourceLocation SourceLocation; - TStringBuf CustomMessage; + + TSourceLocation SourceLocation; + TStringBuf CustomMessage; ELogPriority Priority; -}; - -template <class... R> -struct TLogRecordPreprocessor; - -template <> -struct TLogRecordPreprocessor<> { +}; + +template <class... R> +struct TLogRecordPreprocessor; + +template <> +struct TLogRecordPreprocessor<> { inline static bool CheckLoggingContext(TLog& /*log*/, const TLogRecordContext& /*context*/) { return true; } - inline static TSimpleSharedPtr<TLogElement> StartRecord(TLog& log, const TLogRecordContext& context, TSimpleSharedPtr<TLogElement> earlier) { + inline static TSimpleSharedPtr<TLogElement> StartRecord(TLog& log, const TLogRecordContext& context, TSimpleSharedPtr<TLogElement> earlier) { if (earlier) - return earlier; - TSimpleSharedPtr<TLogElement> result(new TLogElement(&log)); - *result << context.Priority; - return result; - } -}; - -template <class H, class... R> -struct TLogRecordPreprocessor<H, R...> { + return earlier; + TSimpleSharedPtr<TLogElement> result(new TLogElement(&log)); + *result << context.Priority; + return result; + } +}; + +template <class H, class... R> +struct TLogRecordPreprocessor<H, R...> { inline static bool CheckLoggingContext(TLog& log, const TLogRecordContext& context) { return H::CheckLoggingContext(log, context) && TLogRecordPreprocessor<R...>::CheckLoggingContext(log, context); } - inline static TSimpleSharedPtr<TLogElement> StartRecord(TLog& log, const TLogRecordContext& context, TSimpleSharedPtr<TLogElement> earlier) { - TSimpleSharedPtr<TLogElement> first = H::StartRecord(log, context, earlier); - return TLogRecordPreprocessor<R...>::StartRecord(log, context, first); - } -}; - -struct TLogFilter { + inline static TSimpleSharedPtr<TLogElement> StartRecord(TLog& log, const TLogRecordContext& context, TSimpleSharedPtr<TLogElement> earlier) { + TSimpleSharedPtr<TLogElement> first = H::StartRecord(log, context, earlier); + return TLogRecordPreprocessor<R...>::StartRecord(log, context, first); + } +}; + +struct TLogFilter { static bool CheckLoggingContext(TLog& log, const TLogRecordContext& context); static TSimpleSharedPtr<TLogElement> StartRecord(TLog& log, const TLogRecordContext& context, TSimpleSharedPtr<TLogElement> earlier); -}; - -class TNullLog; - -template <class TPreprocessor> -TSimpleSharedPtr<TLogElement> GetLoggerForce(TLog& log, const TLogRecordContext& context) { - if (TSimpleSharedPtr<TLogElement> result = TPreprocessor::StartRecord(log, context, nullptr)) - return result; - return new TLogElement(&TLoggerOperator<TNullLog>::Log()); -} - +}; + +class TNullLog; + +template <class TPreprocessor> +TSimpleSharedPtr<TLogElement> GetLoggerForce(TLog& log, const TLogRecordContext& context) { + if (TSimpleSharedPtr<TLogElement> result = TPreprocessor::StartRecord(log, context, nullptr)) + return result; + return new TLogElement(&TLoggerOperator<TNullLog>::Log()); +} + namespace NPrivateGlobalLogger { struct TEatStream { Y_FORCE_INLINE bool operator|(const IOutputStream&) const { @@ -141,9 +141,9 @@ namespace NPrivateGlobalLogger { }; } -#define LOGGER_GENERIC_LOG_CHECKED(logger, preprocessor, level, message) (*GetLoggerForce<preprocessor>(logger, TLogRecordContext(__LOCATION__, message, level))) +#define LOGGER_GENERIC_LOG_CHECKED(logger, preprocessor, level, message) (*GetLoggerForce<preprocessor>(logger, TLogRecordContext(__LOCATION__, message, level))) #define LOGGER_CHECKED_GENERIC_LOG(logger, preprocessor, level, message) \ (preprocessor::CheckLoggingContext(logger, TLogRecordContext(__LOCATION__, message, level))) && NPrivateGlobalLogger::TEatStream() | (*(preprocessor::StartRecord(logger, TLogRecordContext(__LOCATION__, message, level), nullptr))) - -#define SINGLETON_GENERIC_LOG_CHECKED(type, preprocessor, level, message) LOGGER_GENERIC_LOG_CHECKED(TLoggerOperator<type>::Log(), preprocessor, level, message) -#define SINGLETON_CHECKED_GENERIC_LOG(type, preprocessor, level, message) LOGGER_CHECKED_GENERIC_LOG(TLoggerOperator<type>::Log(), preprocessor, level, message) + +#define SINGLETON_GENERIC_LOG_CHECKED(type, preprocessor, level, message) LOGGER_GENERIC_LOG_CHECKED(TLoggerOperator<type>::Log(), preprocessor, level, message) +#define SINGLETON_CHECKED_GENERIC_LOG(type, preprocessor, level, message) LOGGER_CHECKED_GENERIC_LOG(TLoggerOperator<type>::Log(), preprocessor, level, message) |