|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
Synchronous wrapper ensuring critical logs are never lost. More...
#include <critical_writer.h>


Classes | |
| struct | critical_stats |
| Get statistics about critical writes. More... | |
Public Member Functions | |
| critical_writer (log_writer_ptr wrapped_writer, critical_writer_config config={}) | |
| Constructor. | |
| ~critical_writer () override | |
| Destructor - ensures final flush. | |
| common::VoidResult | write (const log_entry &entry) override |
| Write a log entry with critical handling. | |
| common::VoidResult | flush () override |
| Flush all pending messages. | |
| bool | is_healthy () const override |
| Check if the writer is healthy. | |
| std::string | get_name () const override |
| Get the name of this writer. | |
| void | set_use_color (bool use_color) override |
| Set whether to use color output. | |
| void | set_force_flush_on_critical (bool enable) |
| Enable/disable critical flushing at runtime. | |
| const critical_writer_config & | get_config () const |
| Get current configuration. | |
| const critical_stats & | get_stats () const |
Public Member Functions inherited from kcenon::logger::base_writer | |
| base_writer (std::unique_ptr< log_formatter_interface > formatter=nullptr) | |
| Constructor with optional formatter. | |
| virtual | ~base_writer ()=default |
| bool | use_color () const |
| Get current color output setting. | |
| log_formatter_interface * | get_formatter () const |
| Get the current formatter. | |
Public Member Functions inherited from kcenon::logger::log_writer_interface | |
| virtual | ~log_writer_interface ()=default |
| virtual common::VoidResult | close () |
| Close the writer and release resources. | |
| virtual auto | is_open () const -> bool |
| Check if writer is open and ready. | |
Private Member Functions | |
| bool | is_critical_level (common::interfaces::log_level level) const |
| Check if log level requires critical handling. | |
| void | write_to_wal (const log_entry &entry) |
| Write to write-ahead log. | |
| void | sync_file_descriptor () |
| Force sync of underlying file descriptor. | |
Private Attributes | |
| critical_writer_config | config_ |
| Configuration. | |
| log_writer_ptr | wrapped_writer_ |
| Wrapped writer. | |
| std::mutex | critical_mutex_ |
| Mutex for critical section. | |
| std::unique_ptr< std::ofstream > | wal_stream_ |
| Write-ahead log stream. | |
| critical_stats | stats_ |
| Statistics. | |
| std::atomic< bool > | shutting_down_ {false} |
| Flag for shutdown. | |
Additional Inherited Members | |
Static Public Attributes inherited from kcenon::logger::decorator_writer_tag | |
| static constexpr writer_category | category = writer_category::decorator |
Protected Member Functions inherited from kcenon::logger::base_writer | |
| std::string | format_log_entry (const log_entry &entry) const |
| Format a log entry using the current formatter. | |
Synchronous wrapper ensuring critical logs are never lost.
This writer prevents message loss by:
For signal handling, use signal_manager or crash_safe_logger instead.
Thread Safety: All methods are thread-safe. Critical writes are serialized to ensure ordering and prevent interleaving.
Category: Decorator (wraps another writer to add critical message handling)
Definition at line 103 of file critical_writer.h.
|
explicit |
Constructor.
| wrapped_writer | The underlying writer to wrap |
| config | Configuration options |
| std::invalid_argument | if wrapped_writer is null |
Definition at line 24 of file critical_writer.cpp.
References config_, wrapped_writer_, and kcenon::logger::critical_writer_config::write_ahead_log.
|
override |
Destructor - ensures final flush.
Definition at line 66 of file critical_writer.cpp.
|
overridevirtual |
Flush all pending messages.
Implements kcenon::logger::base_writer.
Definition at line 138 of file critical_writer.cpp.
|
inline |
Get current configuration.
Definition at line 173 of file critical_writer.h.
|
overridevirtual |
Get the name of this writer.
Implements kcenon::logger::base_writer.
Definition at line 162 of file critical_writer.cpp.
|
inline |
Definition at line 185 of file critical_writer.h.
|
private |
Check if log level requires critical handling.
| level | Log level to check |
Definition at line 176 of file critical_writer.cpp.
|
overridevirtual |
Check if the writer is healthy.
Reimplemented from kcenon::logger::base_writer.
Definition at line 153 of file critical_writer.cpp.
| void kcenon::logger::critical_writer::set_force_flush_on_critical | ( | bool | enable | ) |
Enable/disable critical flushing at runtime.
| enable | Enable or disable |
Definition at line 172 of file critical_writer.cpp.
|
overridevirtual |
Set whether to use color output.
| use_color | Enable/disable color output |
Reimplemented from kcenon::logger::base_writer.
Definition at line 166 of file critical_writer.cpp.
|
private |
Force sync of underlying file descriptor.
Definition at line 226 of file critical_writer.cpp.
|
overridevirtual |
Write a log entry with critical handling.
| entry | The log entry to write |
For critical/fatal messages:
For non-critical messages, delegates to wrapped writer normally.
Implements kcenon::logger::base_writer.
Definition at line 83 of file critical_writer.cpp.
References kcenon::logger::log_entry::level.
|
private |
Write to write-ahead log.
| entry | Log entry to write to WAL |
Definition at line 190 of file critical_writer.cpp.
References kcenon::logger::log_entry::level, kcenon::logger::log_entry::location, kcenon::logger::log_entry::message, kcenon::logger::log_entry::timestamp, and kcenon::logger::small_string< SSO_SIZE >::to_string().

|
private |
|
mutableprivate |
Mutex for critical section.
Definition at line 214 of file critical_writer.h.
|
private |
|
mutableprivate |
Statistics.
Definition at line 220 of file critical_writer.h.
|
private |
Write-ahead log stream.
Definition at line 217 of file critical_writer.h.
|
private |