From 29029967dbc66c36e2a6a8ed7c75fce16e4bc530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9C=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=BA=D0=B5=D0=B2=D0=B8=D1=87?= Date: Fri, 17 Oct 2025 14:03:19 +0700 Subject: [PATCH] fup visibility --- glogger.hpp | 94 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 44 insertions(+), 50 deletions(-) diff --git a/glogger.hpp b/glogger.hpp index 0553640..271c432 100644 --- a/glogger.hpp +++ b/glogger.hpp @@ -20,59 +20,11 @@ // Forward declarations class DaemonLogger; -// The Severity enum is defined outside the class to be available to the template helper, -// resolving the incomplete type compilation error. -enum class Severity { Debug, Info, Warning, Error, _Count }; - - -// Вспомогательный шаблонный класс для управления каскадными свойствами -template -class CascadingPropertyResolver { -private: - std::mutex mtx_; - T global_default_; - std::unordered_map category_defaults_; - std::unordered_map> severity_specific_; - -public: - void setGlobal(T value) { - std::lock_guard lock(mtx_); - global_default_ = value; - } - - void setForCategory(const std::string& category, T value) { - std::lock_guard lock(mtx_); - category_defaults_[category] = value; - } - - void setForSeverity(const std::string& category, Severity severity, T value) { - std::lock_guard lock(mtx_); - severity_specific_[category][severity] = value; - } - - T resolve(const std::string& category, Severity severity) { - std::lock_guard lock(mtx_); - // Правило 1: Ищем [категория, уровень] - if (auto cat_it = severity_specific_.find(category); cat_it != severity_specific_.end()) { - if (auto sev_it = cat_it->second.find(severity); sev_it != cat_it->second.end()) { - return sev_it->second; - } - } - // Правило 2: Ищем [категория] - if (auto cat_it = category_defaults_.find(category); cat_it != category_defaults_.end()) { - return cat_it->second; - } - // Правило 3: Используем глобальное значение - return global_default_; - } -}; - class DaemonLogger { public: - // Re-expose Severity enum inside the class for clarity and namespacing, - // while the actual definition is outside. - using Severity = ::Severity; + // Уровни важности сообщений + enum class Severity { Debug, Info, Warning, Error, _Count }; private: // Обертка для потокобезопасной записи в один ostream @@ -177,6 +129,48 @@ public: } private: + // Вспомогательный шаблонный класс для управления каскадными свойствами + template + class CascadingPropertyResolver { + private: + std::mutex mtx_; + T global_default_; + std::unordered_map category_defaults_; + std::unordered_map> severity_specific_; + + public: + void setGlobal(T value) { + std::lock_guard lock(mtx_); + global_default_ = value; + } + + void setForCategory(const std::string& category, T value) { + std::lock_guard lock(mtx_); + category_defaults_[category] = value; + } + + void setForSeverity(const std::string& category, Severity severity, T value) { + std::lock_guard lock(mtx_); + severity_specific_[category][severity] = value; + } + + T resolve(const std::string& category, Severity severity) { + std::lock_guard lock(mtx_); + // Правило 1: Ищем [категория, уровень] + if (auto cat_it = severity_specific_.find(category); cat_it != severity_specific_.end()) { + if (auto sev_it = cat_it->second.find(severity); sev_it != cat_it->second.end()) { + return sev_it->second; + } + } + // Правило 2: Ищем [категория] + if (auto cat_it = category_defaults_.find(category); cat_it != category_defaults_.end()) { + return cat_it->second; + } + // Правило 3: Используем глобальное значение + return global_default_; + } + }; + explicit DaemonLogger(std::string category) : category_(std::move(category)) {} void resolveProperties() {