fup visibility

Сергей Маринкевич 2 months ago
parent 52f9bf2057
commit 6a721eb5ac

BIN
a.out

Binary file not shown.

@ -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

@ -0,0 +1,12 @@
2025-10-17 14:01:25 [DEBUG] <main:48> Это отладочное сообщение для general.log
2025-10-17 14:01:25 [WARN ] <main:49> Это предупреждение для general.log
2025-10-17 14:01:25 [INFO ] <worker_thread_func:13> Worker thread 3 started.
2025-10-17 14:01:25 [INFO ] <worker_thread_func:13> Worker thread 1 started.
2025-10-17 14:01:25 [INFO ] <worker_thread_func:13> Worker thread 5 started.
2025-10-17 14:01:25 [INFO ] <worker_thread_func:13> Worker thread 4 started.
2025-10-17 14:01:25 [INFO ] <worker_thread_func:13> Worker thread 2 started.
2025-10-17 14:01:25 [INFO ] <worker_thread_func:19> Worker thread 3 finished.
2025-10-17 14:01:25 [INFO ] <worker_thread_func:19> Worker thread 5 finished.
2025-10-17 14:01:25 [INFO ] <worker_thread_func:19> Worker thread 1 finished.
2025-10-17 14:01:25 [INFO ] <worker_thread_func:19> Worker thread 4 finished.
2025-10-17 14:01:25 [INFO ] <worker_thread_func:19> Worker thread 2 finished.

@ -20,59 +20,11 @@
// Forward declarations // Forward declarations
class DaemonLogger; 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 <typename T>
class CascadingPropertyResolver {
private:
std::mutex mtx_;
T global_default_;
std::unordered_map<std::string, T> category_defaults_;
std::unordered_map<std::string, std::unordered_map<Severity, T>> severity_specific_;
public:
void setGlobal(T value) {
std::lock_guard<std::mutex> lock(mtx_);
global_default_ = value;
}
void setForCategory(const std::string& category, T value) {
std::lock_guard<std::mutex> lock(mtx_);
category_defaults_[category] = value;
}
void setForSeverity(const std::string& category, Severity severity, T value) {
std::lock_guard<std::mutex> lock(mtx_);
severity_specific_[category][severity] = value;
}
T resolve(const std::string& category, Severity severity) {
std::lock_guard<std::mutex> 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 { class DaemonLogger {
public: public:
// Re-expose Severity enum inside the class for clarity and namespacing, // Уровни важности сообщений
// while the actual definition is outside. enum class Severity { Debug, Info, Warning, Error, _Count };
using Severity = ::Severity;
private: private:
// Обертка для потокобезопасной записи в один ostream // Обертка для потокобезопасной записи в один ostream
@ -177,6 +129,48 @@ public:
} }
private: private:
// Вспомогательный шаблонный класс для управления каскадными свойствами
template <typename T>
class CascadingPropertyResolver {
private:
std::mutex mtx_;
T global_default_;
std::unordered_map<std::string, T> category_defaults_;
std::unordered_map<std::string, std::unordered_map<Severity, T>> severity_specific_;
public:
void setGlobal(T value) {
std::lock_guard<std::mutex> lock(mtx_);
global_default_ = value;
}
void setForCategory(const std::string& category, T value) {
std::lock_guard<std::mutex> lock(mtx_);
category_defaults_[category] = value;
}
void setForSeverity(const std::string& category, Severity severity, T value) {
std::lock_guard<std::mutex> lock(mtx_);
severity_specific_[category][severity] = value;
}
T resolve(const std::string& category, Severity severity) {
std::lock_guard<std::mutex> 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)) {} explicit DaemonLogger(std::string category) : category_(std::move(category)) {}
void resolveProperties() { void resolveProperties() {

@ -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
Loading…
Cancel
Save