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/backend.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/logger/backend.cpp')
-rw-r--r-- | library/cpp/logger/backend.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/library/cpp/logger/backend.cpp b/library/cpp/logger/backend.cpp new file mode 100644 index 00000000000..b26bf5e88ce --- /dev/null +++ b/library/cpp/logger/backend.cpp @@ -0,0 +1,71 @@ +#include "backend.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: + TVector<TLogBackend*> Backends; + 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; + } + } + Y_FAIL("Incorrect pointer for log backend"); + } + + void Reopen(bool flush) { + 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; +}; + +ELogPriority TLogBackend::FiltrationLevel() const { + return LOG_MAX_PRIORITY; +} + +TLogBackend::TLogBackend() noexcept { + Singleton<TGlobalLogsStorage>()->Register(this); +} + +TLogBackend::~TLogBackend() { + Singleton<TGlobalLogsStorage>()->UnRegister(this); +} + +void TLogBackend::ReopenLogNoFlush() { + ReopenLog(); +} + +void TLogBackend::ReopenAllBackends(bool flush) { + Singleton<TGlobalLogsStorage>()->Reopen(flush); +} + +size_t TLogBackend::QueueSize() const { + ythrow yexception() << "Not implemented."; +} |