diff --git a/a.out b/a.out new file mode 100755 index 0000000..2e40880 Binary files /dev/null and b/a.out differ diff --git a/critical.log b/critical.log new file mode 100644 index 0000000..8d4acd3 --- /dev/null +++ b/critical.log @@ -0,0 +1,3 @@ +!!! CRITICAL [General] 2025-10-17 14:01:25 !!! Критическая ошибка, которая пойдет в critical.log @ main:51 +!!! CRITICAL [General] 2025-10-17 14:01:25 !!! Simulated failure in even thread 4 @ worker_thread_func:17 +!!! CRITICAL [General] 2025-10-17 14:01:25 !!! Simulated failure in even thread 2 @ worker_thread_func:17 diff --git a/general.log b/general.log new file mode 100644 index 0000000..c43a556 --- /dev/null +++ b/general.log @@ -0,0 +1,12 @@ +2025-10-17 14:01:25 [DEBUG] Это отладочное сообщение для general.log +2025-10-17 14:01:25 [WARN ] Это предупреждение для general.log +2025-10-17 14:01:25 [INFO ] Worker thread 3 started. +2025-10-17 14:01:25 [INFO ] Worker thread 1 started. +2025-10-17 14:01:25 [INFO ] Worker thread 5 started. +2025-10-17 14:01:25 [INFO ] Worker thread 4 started. +2025-10-17 14:01:25 [INFO ] Worker thread 2 started. +2025-10-17 14:01:25 [INFO ] Worker thread 3 finished. +2025-10-17 14:01:25 [INFO ] Worker thread 5 finished. +2025-10-17 14:01:25 [INFO ] Worker thread 1 finished. +2025-10-17 14:01:25 [INFO ] Worker thread 4 finished. +2025-10-17 14:01:25 [INFO ] Worker thread 2 finished. 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() { diff --git a/network.log b/network.log new file mode 100644 index 0000000..a6737b3 --- /dev/null +++ b/network.log @@ -0,0 +1,8 @@ +2025-10-17 14:01:25 -> New connection from 192.168.1.100 +2025-10-17 14:01:25 -> Packet loss detected: 5% +2025-10-17 14:01:25 -> А эта запись-предупреждение ДОЛЖНА появиться. +2025-10-17 14:01:25 -> heartbeat from thread 3 +2025-10-17 14:01:25 -> heartbeat from thread 1 +2025-10-17 14:01:25 -> heartbeat from thread 5 +2025-10-17 14:01:25 -> heartbeat from thread 4 +2025-10-17 14:01:25 -> heartbeat from thread 2