diff options
author | ivanmorozov <ivanmorozov@yandex-team.ru> | 2022-02-10 16:47:33 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:33 +0300 |
commit | cba5d9a444e2cfe105f55ccda66cd21d50440017 (patch) | |
tree | 79983e83d1a91aebeb1999338090eec69e24cc33 /library/cpp/logger/global/global.h | |
parent | eb540cc7a103419462d0cc870ca403966e2194c6 (diff) | |
download | ydb-cba5d9a444e2cfe105f55ccda66cd21d50440017.tar.gz |
Restoring authorship annotation for <ivanmorozov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/logger/global/global.h')
-rw-r--r-- | library/cpp/logger/global/global.h | 130 |
1 files changed, 65 insertions, 65 deletions
diff --git a/library/cpp/logger/global/global.h b/library/cpp/logger/global/global.h index cbe71b16ea..0692b79c9a 100644 --- a/library/cpp/logger/global/global.h +++ b/library/cpp/logger/global/global.h @@ -1,26 +1,26 @@ -#pragma once - -#include "common.h" +#pragma once + +#include "common.h" #include "rty_formater.h" - -// ATTENTION! MUST CALL DoInitGlobalLog BEFORE USAGE - + +// ATTENTION! MUST CALL DoInitGlobalLog BEFORE USAGE + bool GlobalLogInitialized(); void DoInitGlobalLog(const TString& logType, const int logLevel, const bool rotation, const bool startAsDaemon, THolder<ILoggerFormatter> formatter = {}, bool threaded = false); void DoInitGlobalLog(THolder<TLogBackend> backend, THolder<ILoggerFormatter> formatter = {}); - -inline void InitGlobalLog2Null() { + +inline void InitGlobalLog2Null() { DoInitGlobalLog("null", TLOG_EMERG, false, false); -} - -inline void InitGlobalLog2Console(int loglevel = TLOG_INFO) { - DoInitGlobalLog("console", loglevel, false, false); -} - -class TGlobalLog: public TLog { -public: +} + +inline void InitGlobalLog2Console(int loglevel = TLOG_INFO) { + DoInitGlobalLog("console", loglevel, false, false); +} + +class TGlobalLog: public TLog { +public: TGlobalLog(const TString& logType, ELogPriority priority = LOG_MAX_PRIORITY) - : TLog(logType, priority) + : TLog(logType, priority) { } @@ -28,15 +28,15 @@ public: : TLog(std::move(backend)) { } -}; - +}; + template <> TGlobalLog* CreateDefaultLogger<TGlobalLog>(); -class TNullLog: public TLog { -public: +class TNullLog: public TLog { +public: TNullLog(const TString& logType, ELogPriority priority = LOG_MAX_PRIORITY) - : TLog(logType, priority) + : TLog(logType, priority) { } @@ -44,8 +44,8 @@ public: : TLog(std::move(backend)) { } -}; - +}; + template <> TNullLog* CreateDefaultLogger<TNullLog>(); @@ -62,21 +62,21 @@ public: }; #define FATAL_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_CRIT, "CRITICAL_INFO") -#define ALERT_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_ALERT, "ALERT") +#define ALERT_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_ALERT, "ALERT") #define ERROR_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_ERR, "ERROR") #define WARNING_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_WARNING, "WARNING") #define NOTICE_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_NOTICE, "NOTICE") #define INFO_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_INFO, "INFO") #define DEBUG_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_DEBUG, "DEBUG") #define RESOURCES_LOG SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, TLOG_RESOURCES, "RESOURCES") - + #define TEMPLATE_LOG(logLevel) SINGLETON_CHECKED_GENERIC_LOG(TGlobalLog, TRTYLogPreprocessor, logLevel, ToString(logLevel).data()) -#define IS_LOG_ACTIVE(logLevel) (TLoggerOperator<TGlobalLog>::Log().FiltrationLevel() >= logLevel) - +#define IS_LOG_ACTIVE(logLevel) (TLoggerOperator<TGlobalLog>::Log().FiltrationLevel() >= logLevel) + #define RTY_MEM_LOG(Action) \ { NOTICE_LOG << "RESOURCES On " << Action << ": " << NLoggingImpl::GetSystemResources() << Endl; }; - + #define VERIFY_WITH_LOG(expr, msg, ...) \ do { \ if (Y_UNLIKELY(!(expr))) { \ @@ -84,42 +84,42 @@ public: Y_VERIFY(false, msg, ##__VA_ARGS__); \ }; \ } while (0); - -namespace NPrivateGlobalLogger { - class TVerifyEvent: public TStringStream { - public: - ~TVerifyEvent(); - template <class T> + +namespace NPrivateGlobalLogger { + class TVerifyEvent: public TStringStream { + public: + ~TVerifyEvent(); + template <class T> inline TVerifyEvent& operator<<(const T& t) { static_cast<IOutputStream&>(*this) << t; - - return *this; - } - }; - class TNullStream: public TStringStream { - public: - ~TNullStream() = default; - - template <class T> - inline TNullStream& operator<<(const T& /*t*/) { - return *this; - } - }; -} - -#define CHECK_WITH_LOG(expr) \ - Y_UNLIKELY(!(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TVerifyEvent() << __LOCATION__ << ": " << #expr << "(verification failed!): " - -#if !defined(NDEBUG) && !defined(__GCCXML__) -#define ASSERT_WITH_LOG(expr) \ - Y_UNLIKELY(!(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TVerifyEvent() << __LOCATION__ << ": " << #expr << "(verification failed!): " -#else -#define ASSERT_WITH_LOG(expr) \ - Y_UNLIKELY(false && !(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TNullStream() -#endif - -#define CHECK_EQ_WITH_LOG(a, b) CHECK_WITH_LOG((a) == (b)) << a << " != " << b; -#define CHECK_LEQ_WITH_LOG(a, b) CHECK_WITH_LOG((a) <= (b)) << a << " > " << b; - + + return *this; + } + }; + class TNullStream: public TStringStream { + public: + ~TNullStream() = default; + + template <class T> + inline TNullStream& operator<<(const T& /*t*/) { + return *this; + } + }; +} + +#define CHECK_WITH_LOG(expr) \ + Y_UNLIKELY(!(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TVerifyEvent() << __LOCATION__ << ": " << #expr << "(verification failed!): " + +#if !defined(NDEBUG) && !defined(__GCCXML__) +#define ASSERT_WITH_LOG(expr) \ + Y_UNLIKELY(!(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TVerifyEvent() << __LOCATION__ << ": " << #expr << "(verification failed!): " +#else +#define ASSERT_WITH_LOG(expr) \ + Y_UNLIKELY(false && !(expr)) && NPrivateGlobalLogger::TEatStream() | NPrivateGlobalLogger::TNullStream() +#endif + +#define CHECK_EQ_WITH_LOG(a, b) CHECK_WITH_LOG((a) == (b)) << a << " != " << b; +#define CHECK_LEQ_WITH_LOG(a, b) CHECK_WITH_LOG((a) <= (b)) << a << " > " << b; + #define FAIL_LOG(msg, ...) VERIFY_WITH_LOG(false, msg, ##__VA_ARGS__) -#define S_FAIL_LOG CHECK_WITH_LOG(false) +#define S_FAIL_LOG CHECK_WITH_LOG(false) |