diff --git a/glogger.hpp b/glogger.hpp index 0553640..8acd929 100644 --- a/glogger.hpp +++ b/glogger.hpp @@ -17,62 +17,10 @@ #include -// 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 +125,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() {