aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/logger
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.ru>2022-02-10 16:47:33 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:33 +0300
commitcba5d9a444e2cfe105f55ccda66cd21d50440017 (patch)
tree79983e83d1a91aebeb1999338090eec69e24cc33 /library/cpp/logger
parenteb540cc7a103419462d0cc870ca403966e2194c6 (diff)
downloadydb-cba5d9a444e2cfe105f55ccda66cd21d50440017.tar.gz
Restoring authorship annotation for <ivanmorozov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/logger')
-rw-r--r--library/cpp/logger/backend.cpp84
-rw-r--r--library/cpp/logger/backend.h2
-rw-r--r--library/cpp/logger/filter.cpp2
-rw-r--r--library/cpp/logger/filter.h44
-rw-r--r--library/cpp/logger/global/common.cpp2
-rw-r--r--library/cpp/logger/global/common.h18
-rw-r--r--library/cpp/logger/global/global.cpp16
-rw-r--r--library/cpp/logger/global/global.h130
-rw-r--r--library/cpp/logger/global/ya.make8
-rw-r--r--library/cpp/logger/log.cpp12
-rw-r--r--library/cpp/logger/log.h2
11 files changed, 160 insertions, 160 deletions
diff --git a/library/cpp/logger/backend.cpp b/library/cpp/logger/backend.cpp
index b26bf5e88c..e0ea81471d 100644
--- a/library/cpp/logger/backend.cpp
+++ b/library/cpp/logger/backend.cpp
@@ -1,66 +1,66 @@
#include "backend.h"
-#include <util/generic/vector.h>
-#include <util/system/mutex.h>
-#include <util/generic/singleton.h>
+#include <util/generic/vector.h>
+#include <util/system/mutex.h>
+#include <util/generic/singleton.h>
#include <util/generic/yexception.h>
-namespace {
- class TGlobalLogsStorage {
- private:
+namespace {
+ class TGlobalLogsStorage {
+ private:
TVector<TLogBackend*> Backends;
- TMutex Mutex;
+ TMutex Mutex;
- public:
- void Register(TLogBackend* backend) {
- TGuard<TMutex> g(Mutex);
- Backends.push_back(backend);
- }
-
- void UnRegister(TLogBackend* backend) {
- TGuard<TMutex> g(Mutex);
- for (ui32 i = 0; i < Backends.size(); ++i) {
- if (Backends[i] == backend) {
- Backends.erase(Backends.begin() + i);
- return;
- }
- }
+ public:
+ void Register(TLogBackend* backend) {
+ TGuard<TMutex> g(Mutex);
+ Backends.push_back(backend);
+ }
+
+ void UnRegister(TLogBackend* backend) {
+ TGuard<TMutex> g(Mutex);
+ for (ui32 i = 0; i < Backends.size(); ++i) {
+ if (Backends[i] == backend) {
+ Backends.erase(Backends.begin() + i);
+ return;
+ }
+ }
Y_FAIL("Incorrect pointer for log backend");
- }
-
+ }
+
void Reopen(bool flush) {
- TGuard<TMutex> g(Mutex);
- for (auto& b : Backends) {
+ TGuard<TMutex> g(Mutex);
+ for (auto& b : Backends) {
if (flush) {
b->ReopenLog();
} else {
b->ReopenLogNoFlush();
}
- }
- }
- };
-}
-
+ }
+ }
+ };
+}
+
template <>
-class TSingletonTraits<TGlobalLogsStorage> {
-public:
- static const size_t Priority = 50;
-};
-
+class TSingletonTraits<TGlobalLogsStorage> {
+public:
+ static const size_t Priority = 50;
+};
+
ELogPriority TLogBackend::FiltrationLevel() const {
- return LOG_MAX_PRIORITY;
-}
-
+ return LOG_MAX_PRIORITY;
+}
+
TLogBackend::TLogBackend() noexcept {
- Singleton<TGlobalLogsStorage>()->Register(this);
+ Singleton<TGlobalLogsStorage>()->Register(this);
}
TLogBackend::~TLogBackend() {
- Singleton<TGlobalLogsStorage>()->UnRegister(this);
+ Singleton<TGlobalLogsStorage>()->UnRegister(this);
}
-
+
void TLogBackend::ReopenLogNoFlush() {
ReopenLog();
-}
+}
void TLogBackend::ReopenAllBackends(bool flush) {
Singleton<TGlobalLogsStorage>()->Reopen(flush);
diff --git a/library/cpp/logger/backend.h b/library/cpp/logger/backend.h
index d088726d6d..791771ced9 100644
--- a/library/cpp/logger/backend.h
+++ b/library/cpp/logger/backend.h
@@ -23,7 +23,7 @@ public:
virtual void ReopenLogNoFlush();
virtual ELogPriority FiltrationLevel() const;
-
+
static void ReopenAllBackends(bool flush = true);
virtual size_t QueueSize() const;
diff --git a/library/cpp/logger/filter.cpp b/library/cpp/logger/filter.cpp
index 300ac6b595..2007e4e56a 100644
--- a/library/cpp/logger/filter.cpp
+++ b/library/cpp/logger/filter.cpp
@@ -1 +1 @@
-#include "filter.h"
+#include "filter.h"
diff --git a/library/cpp/logger/filter.h b/library/cpp/logger/filter.h
index 9ef83fb58c..4cc66ff512 100644
--- a/library/cpp/logger/filter.h
+++ b/library/cpp/logger/filter.h
@@ -1,32 +1,32 @@
-#pragma once
+#pragma once
-#include "priority.h"
-#include "record.h"
-#include "backend.h"
-#include <util/generic/ptr.h>
-
-class TFilteredLogBackend: public TLogBackend {
+#include "priority.h"
+#include "record.h"
+#include "backend.h"
+#include <util/generic/ptr.h>
+
+class TFilteredLogBackend: public TLogBackend {
THolder<TLogBackend> Backend;
ELogPriority Level;
-public:
+public:
TFilteredLogBackend(THolder<TLogBackend>&& t, ELogPriority level = LOG_MAX_PRIORITY) noexcept
: Backend(std::move(t))
- , Level(level)
- {
- }
-
+ , Level(level)
+ {
+ }
+
ELogPriority FiltrationLevel() const override {
- return Level;
- }
-
+ return Level;
+ }
+
void ReopenLog() override {
- Backend->ReopenLog();
- }
-
+ Backend->ReopenLog();
+ }
+
void WriteData(const TLogRecord& rec) override {
if (rec.Priority <= (ELogPriority)Level) {
- Backend->WriteData(rec);
- }
- }
-};
+ Backend->WriteData(rec);
+ }
+ }
+};
diff --git a/library/cpp/logger/global/common.cpp b/library/cpp/logger/global/common.cpp
index 4fb05c19b4..844936cebe 100644
--- a/library/cpp/logger/global/common.cpp
+++ b/library/cpp/logger/global/common.cpp
@@ -1,4 +1,4 @@
-#include "common.h"
+#include "common.h"
#include <util/generic/yexception.h>
diff --git a/library/cpp/logger/global/common.h b/library/cpp/logger/global/common.h
index 7dcf650dec..52daf1f5be 100644
--- a/library/cpp/logger/global/common.h
+++ b/library/cpp/logger/global/common.h
@@ -12,10 +12,10 @@
#include <library/cpp/logger/log.h>
-namespace NLoggingImpl {
- const size_t SingletonPriority = 500;
-}
-
+namespace NLoggingImpl {
+ const size_t SingletonPriority = 500;
+}
+
template <class T>
T* CreateDefaultLogger() {
return nullptr;
@@ -35,15 +35,15 @@ namespace NLoggingImpl {
public:
inline static bool Usage() {
- return SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Get();
+ return SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Get();
}
inline static T* Get() {
- return SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Get();
+ return SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Get();
}
inline static void Set(T* v) {
- SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Reset(v);
+ SingletonWithPriority<TPtr, SingletonPriority>()->Instance.Reset(v);
}
};
@@ -62,8 +62,8 @@ public:
Y_ASSERT(TLoggerOperator::Usage());
return *TLoggerOperator::Get();
}
-};
-
+};
+
namespace NLoggingImpl {
TString GetLocalTimeSSimple();
diff --git a/library/cpp/logger/global/global.cpp b/library/cpp/logger/global/global.cpp
index 9fbd10f666..1a9dc8c1c7 100644
--- a/library/cpp/logger/global/global.cpp
+++ b/library/cpp/logger/global/global.cpp
@@ -1,12 +1,12 @@
-#include "global.h"
-
+#include "global.h"
+
static void DoInitGlobalLog(THolder<TGlobalLog> logger, THolder<ILoggerFormatter> formatter) {
TLoggerOperator<TGlobalLog>::Set(logger.Release());
if (!formatter) {
formatter.Reset(CreateRtyLoggerFormatter());
}
TLoggerFormatterOperator::Set(formatter.Release());
-}
+}
void DoInitGlobalLog(const TString& logType, const int logLevel, const bool rotation, const bool startAsDaemon, THolder<ILoggerFormatter> formatter, bool threaded) {
DoInitGlobalLog(
@@ -35,9 +35,9 @@ template <>
TNullLog* CreateDefaultLogger<TNullLog>() {
return new TNullLog("null");
}
-
-NPrivateGlobalLogger::TVerifyEvent::~TVerifyEvent() {
- const TString info = Str();
- FATAL_LOG << info << Endl;
+
+NPrivateGlobalLogger::TVerifyEvent::~TVerifyEvent() {
+ const TString info = Str();
+ FATAL_LOG << info << Endl;
Y_FAIL("%s", info.data());
-}
+}
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)
diff --git a/library/cpp/logger/global/ya.make b/library/cpp/logger/global/ya.make
index 20eb361e72..843f01016c 100644
--- a/library/cpp/logger/global/ya.make
+++ b/library/cpp/logger/global/ya.make
@@ -6,10 +6,10 @@ PEERDIR(
library/cpp/logger
)
-IF (OS_WINDOWS)
- NO_WERROR()
-ENDIF()
-
+IF (OS_WINDOWS)
+ NO_WERROR()
+ENDIF()
+
SRCS(
common.cpp
global.cpp
diff --git a/library/cpp/logger/log.cpp b/library/cpp/logger/log.cpp
index e1d70cc3d2..23bfea0e0c 100644
--- a/library/cpp/logger/log.cpp
+++ b/library/cpp/logger/log.cpp
@@ -101,13 +101,13 @@ public:
inline void WriteData(ELogPriority priority, const char* data, size_t len) const {
if (IsOpen()) {
Backend_->WriteData(TLogRecord(priority, data, len));
- }
+ }
}
-
+
inline ELogPriority DefaultPriority() noexcept {
return DefaultPriority_;
}
-
+
inline void SetDefaultPriority(ELogPriority priority) noexcept {
DefaultPriority_ = priority;
}
@@ -197,9 +197,9 @@ void TLog::SetDefaultPriority(ELogPriority priority) noexcept {
}
ELogPriority TLog::FiltrationLevel() const noexcept {
- return Impl_->FiltrationLevel();
-}
-
+ return Impl_->FiltrationLevel();
+}
+
ELogPriority TLog::DefaultPriority() const noexcept {
return Impl_->DefaultPriority();
}
diff --git a/library/cpp/logger/log.h b/library/cpp/logger/log.h
index 8be984ccc8..09ab9ba1a5 100644
--- a/library/cpp/logger/log.h
+++ b/library/cpp/logger/log.h
@@ -85,7 +85,7 @@ public:
// Call `FiltrationLevel()` of the underlying backend.
ELogPriority FiltrationLevel() const noexcept;
-
+
// Set current log formatter.
void SetFormatter(TLogFormatter formatter) noexcept;