|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
Logger with crash recovery and emergency flush capabilities. More...
#include <crash_safe_logger.h>

Public Member Functions | |
| bool | install_crash_handlers () |
| Install signal handlers for crash detection. | |
| void | uninstall_crash_handlers () |
| Remove signal handlers. | |
| bool | flush_with_timeout (std::chrono::milliseconds timeout) |
| Flush with timeout to prevent deadlocks. | |
| void | emergency_flush () |
| Emergency flush (async-signal-safe) | |
| void | set_min_level (log_level level) |
| Set minimum log level (thread-safe) | |
| log_level | get_min_level () const |
| Get minimum log level (thread-safe) | |
| void | set_auto_flush_interval (std::chrono::milliseconds interval) |
| Enable auto-flush at regular intervals. | |
| void | log (log_level level, const std::string &message) |
| Log message (delegates to underlying logger) | |
| void | log (log_level level, const std::string &message, const std::string &file, int line, const std::string &function) |
| Log message with source location. | |
| common::VoidResult | start () |
| Start the underlying logger. | |
| common::VoidResult | stop () |
| Stop the underlying logger. | |
| std::shared_ptr< logger > | get_underlying_logger () |
| Get the underlying logger. | |
| ~crash_safe_logger () | |
Static Public Member Functions | |
| static std::shared_ptr< crash_safe_logger > | create (std::shared_ptr< logger > underlying_logger=nullptr) |
| Create crash-safe logger. | |
Private Member Functions | |
| crash_safe_logger (std::shared_ptr< logger > logger) | |
| void | start_auto_flush_thread () |
| Start auto-flush background thread. | |
| void | stop_auto_flush_thread () |
| Stop auto-flush background thread. | |
Static Private Member Functions | |
| static void | signal_handler (int signal) |
| Signal handler (async-signal-safe) | |
Private Attributes | |
| std::shared_ptr< logger > | logger_ |
| std::atomic< log_level > | min_level_ |
| std::mutex | handler_mutex_ |
| bool | handlers_installed_ |
| struct sigaction | old_sigsegv_ |
| struct sigaction | old_sigabrt_ |
| struct sigaction | old_sigterm_ |
| struct sigaction | old_sigint_ |
| std::atomic< bool > | emergency_flush_active_ |
| std::atomic< bool > | flush_requested_ |
| std::mutex | flush_mutex_ |
| std::chrono::milliseconds | auto_flush_interval_ |
| std::thread | auto_flush_thread_ |
| std::atomic< bool > | stop_auto_flush_ |
Static Private Attributes | |
| static std::weak_ptr< crash_safe_logger > | global_instance_ |
Logger with crash recovery and emergency flush capabilities.
This logger wrapper provides additional safety guarantees:
All methods are thread-safe. Signal handlers use async-signal-safe operations only.
Definition at line 61 of file crash_safe_logger.h.
|
inline |
Definition at line 254 of file crash_safe_logger.h.
References stop_auto_flush_thread(), and uninstall_crash_handlers().

|
inlineexplicitprivate |
Definition at line 260 of file crash_safe_logger.h.
Referenced by create().

|
inlinestatic |
Create crash-safe logger.
| underlying_logger | Base logger to wrap (optional) |
Definition at line 68 of file crash_safe_logger.h.
References crash_safe_logger(), and global_instance_.

|
inline |
Emergency flush (async-signal-safe)
This is called from signal handlers and must be async-signal-safe. It attempts a best-effort flush without allocations or locks.
Definition at line 165 of file crash_safe_logger.h.
References emergency_flush_active_, flush_mutex_, and logger_.
|
inline |
Flush with timeout to prevent deadlocks.
| timeout | Maximum time to wait for flush |
Definition at line 135 of file crash_safe_logger.h.
References flush_mutex_, flush_requested_, and logger_.
Referenced by start_auto_flush_thread().

|
inline |
Get minimum log level (thread-safe)
Definition at line 187 of file crash_safe_logger.h.
References min_level_.
|
inline |
|
inline |
Install signal handlers for crash detection.
Definition at line 89 of file crash_safe_logger.h.
References handler_mutex_, handlers_installed_, old_sigabrt_, old_sigint_, old_sigsegv_, old_sigterm_, signal_handler(), and kcenon::logger::success.

|
inline |
Log message (delegates to underlying logger)
Definition at line 208 of file crash_safe_logger.h.
References logger_, and min_level_.
|
inline |
Log message with source location.
Definition at line 220 of file crash_safe_logger.h.
References logger_, and min_level_.
|
inline |
Enable auto-flush at regular intervals.
| interval | Time between auto-flushes |
Definition at line 195 of file crash_safe_logger.h.
References auto_flush_interval_, auto_flush_thread_, start_auto_flush_thread(), and stop_auto_flush_thread().

|
inline |
Set minimum log level (thread-safe)
Definition at line 179 of file crash_safe_logger.h.
References logger_, and min_level_.
|
inlinestaticprivate |
Signal handler (async-signal-safe)
Definition at line 274 of file crash_safe_logger.h.
References global_instance_.
Referenced by install_crash_handlers().

|
inline |
Start the underlying logger.
Definition at line 235 of file crash_safe_logger.h.
References logger_.
|
inlineprivate |
Start auto-flush background thread.
Definition at line 309 of file crash_safe_logger.h.
References auto_flush_interval_, auto_flush_thread_, flush_with_timeout(), and stop_auto_flush_.
Referenced by set_auto_flush_interval().


|
inline |
Stop the underlying logger.
Definition at line 242 of file crash_safe_logger.h.
References logger_, and stop_auto_flush_thread().

|
inlineprivate |
Stop auto-flush background thread.
Definition at line 325 of file crash_safe_logger.h.
References auto_flush_thread_, and stop_auto_flush_.
Referenced by set_auto_flush_interval(), stop(), and ~crash_safe_logger().

|
inline |
Remove signal handlers.
Definition at line 115 of file crash_safe_logger.h.
References handler_mutex_, handlers_installed_, old_sigabrt_, old_sigint_, old_sigsegv_, and old_sigterm_.
Referenced by ~crash_safe_logger().

|
private |
Definition at line 350 of file crash_safe_logger.h.
Referenced by set_auto_flush_interval(), and start_auto_flush_thread().
|
private |
Definition at line 351 of file crash_safe_logger.h.
Referenced by set_auto_flush_interval(), start_auto_flush_thread(), and stop_auto_flush_thread().
|
private |
Definition at line 345 of file crash_safe_logger.h.
Referenced by emergency_flush().
|
private |
Definition at line 347 of file crash_safe_logger.h.
Referenced by emergency_flush(), and flush_with_timeout().
|
private |
Definition at line 346 of file crash_safe_logger.h.
Referenced by flush_with_timeout().
|
staticprivate |
Definition at line 355 of file crash_safe_logger.h.
Referenced by create(), and signal_handler().
|
private |
Definition at line 337 of file crash_safe_logger.h.
Referenced by install_crash_handlers(), and uninstall_crash_handlers().
|
private |
Definition at line 338 of file crash_safe_logger.h.
Referenced by install_crash_handlers(), and uninstall_crash_handlers().
|
private |
Definition at line 333 of file crash_safe_logger.h.
Referenced by emergency_flush(), flush_with_timeout(), get_underlying_logger(), log(), log(), set_min_level(), start(), and stop().
|
private |
Definition at line 334 of file crash_safe_logger.h.
Referenced by get_min_level(), log(), log(), and set_min_level().
|
private |
Definition at line 340 of file crash_safe_logger.h.
Referenced by install_crash_handlers(), and uninstall_crash_handlers().
|
private |
Definition at line 342 of file crash_safe_logger.h.
Referenced by install_crash_handlers(), and uninstall_crash_handlers().
|
private |
Definition at line 339 of file crash_safe_logger.h.
Referenced by install_crash_handlers(), and uninstall_crash_handlers().
|
private |
Definition at line 341 of file crash_safe_logger.h.
Referenced by install_crash_handlers(), and uninstall_crash_handlers().
|
private |
Definition at line 352 of file crash_safe_logger.h.
Referenced by start_auto_flush_thread(), and stop_auto_flush_thread().