|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Structured logger for thread system. More...
#include <thread_logger.h>

Public Member Functions | |
| void | set_enabled (bool enabled) |
| Enable/disable logging. | |
| bool | is_enabled () const |
| Check if logging is enabled. | |
| void | set_level (log_level level) |
| Set minimum log level. | |
| void | log (log_level level, std::string_view thread_name, std::string_view message, std::string_view context="") |
| Log a message with context. | |
| template<typename ErrorType > | |
| void | log_error (std::string_view thread_name, const ErrorType &error) |
| Log error with error code. | |
| void | set_lightweight_mode (bool enabled) |
| Enable lightweight mode (disables all logging for maximum performance). | |
| bool | is_lightweight_mode () const |
| Check if in lightweight mode. | |
Static Public Member Functions | |
| static thread_logger & | instance () |
| Get singleton instance. | |
| static void | prepare_shutdown () |
| Prepare for process shutdown. | |
| static bool | is_shutting_down () |
| Check if shutdown is in progress. | |
Private Member Functions | |
| thread_logger ()=default | |
| ~thread_logger ()=default | |
| thread_logger (const thread_logger &)=delete | |
| thread_logger & | operator= (const thread_logger &)=delete |
Static Private Member Functions | |
| static const char * | level_to_string (log_level level) |
Private Attributes | |
| bool | enabled_ = true |
| log_level | min_level_ = log_level::warning |
| std::mutex | mutex_ |
| bool | lightweight_mode_ = false |
Static Private Attributes | |
| static std::atomic< bool > | is_shutting_down_ {false} |
Structured logger for thread system.
Provides thread-safe, structured logging with timestamps, thread IDs, and severity levels for better diagnostics.
Thread Safety:
SDOF Prevention:
Definition at line 71 of file thread_logger.h.
|
privatedefault |
|
privatedefault |
|
privatedelete |
|
inlinestatic |
Get singleton instance.
Uses intentional leak pattern to avoid static destruction order issues. The logger may be accessed during other singletons' destruction, so we intentionally leak to ensure it remains valid.
Definition at line 88 of file thread_logger.h.
References prepare_shutdown(), and thread_logger().
Referenced by kcenon::thread::thread_base::start().


|
inline |
Check if logging is enabled.
thread_context::has_logger() instead. Will be removed in v2.0.0. Definition at line 144 of file thread_logger.h.
References enabled_.
|
inline |
Check if in lightweight mode.
set_lightweight_mode deprecation. Will be removed in v2.0.0. Definition at line 308 of file thread_logger.h.
References lightweight_mode_.
|
inlinestatic |
Check if shutdown is in progress.
Definition at line 117 of file thread_logger.h.
References is_shutting_down_.
Referenced by kcenon::thread::thread_context::log(), kcenon::thread::thread_context::log(), kcenon::thread::thread_context::log(), kcenon::thread::thread_context::update_system_metrics(), kcenon::thread::thread_context::update_thread_pool_metrics(), kcenon::thread::thread_context::update_thread_pool_metrics(), kcenon::thread::thread_context::update_worker_metrics(), and kcenon::thread::thread_pool::~thread_pool().

|
inlinestaticprivate |
Definition at line 252 of file thread_logger.h.
References kcenon::thread::critical, kcenon::thread::debug, kcenon::thread::error, kcenon::thread::info, kcenon::thread::trace, and kcenon::thread::warning.
Referenced by log().

|
inline |
Log a message with context.
| level | Severity level |
| thread_name | Thread identifier |
| message | Log message |
| context | Additional context (optional) |
thread_context::log() backed by common::interfaces::ILogger instead. Will be removed in v2.0.0. Definition at line 176 of file thread_logger.h.
References enabled_, is_shutting_down_, level_to_string(), min_level_, and mutex_.
Referenced by log_error(), and kcenon::thread::thread_base::start().


|
inline |
Log error with error code.
thread_context::log() with a common::interfaces::ILogger implementation instead. Will be removed in v2.0.0. Definition at line 229 of file thread_logger.h.
References kcenon::thread::error::code(), enabled_, kcenon::thread::error, is_shutting_down_, log(), and kcenon::thread::error::message().

|
privatedelete |
|
inlinestatic |
Prepare for process shutdown.
Call this before process termination to prevent log calls during static destruction. Once called, all log operations become no-ops.
Definition at line 110 of file thread_logger.h.
References is_shutting_down_.
Referenced by instance().

|
inline |
Enable/disable logging.
common::interfaces::ILogger via thread_context and control logging through its implementation instead. Will be removed in v2.0.0. Definition at line 131 of file thread_logger.h.
References enabled_.
|
inline |
Set minimum log level.
common::interfaces::ILogger implementation instead. Will be removed in v2.0.0. Definition at line 158 of file thread_logger.h.
References min_level_.
|
inline |
Enable lightweight mode (disables all logging for maximum performance).
In lightweight mode, all log calls become no-ops with minimal overhead. Useful for performance-critical production deployments where diagnostics are handled externally.
| enabled | true to enable lightweight mode, false to use normal logging |
common::interfaces::ILogger, a null logger in thread_context achieves the same effect without this toggle. Will be removed in v2.0.0. Definition at line 291 of file thread_logger.h.
References enabled_, and lightweight_mode_.
|
private |
Definition at line 266 of file thread_logger.h.
Referenced by is_enabled(), log(), log_error(), set_enabled(), and set_lightweight_mode().
|
inlinestaticprivate |
Definition at line 245 of file thread_logger.h.
Referenced by is_shutting_down(), log(), log_error(), and prepare_shutdown().
|
private |
Definition at line 272 of file thread_logger.h.
Referenced by is_lightweight_mode(), and set_lightweight_mode().
|
private |
Definition at line 267 of file thread_logger.h.
Referenced by log(), and set_level().
|
private |
Definition at line 268 of file thread_logger.h.
Referenced by log().