|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
Base class providing automatic thread-safety for writer implementations. More...
#include <thread_safe_writer.h>


Public Member Functions | |
| thread_safe_writer (std::unique_ptr< log_formatter_interface > formatter=nullptr) | |
| Constructor with optional formatter. | |
| ~thread_safe_writer () override=default | |
| Virtual destructor. | |
| thread_safe_writer (const thread_safe_writer &)=delete | |
| thread_safe_writer & | operator= (const thread_safe_writer &)=delete |
| thread_safe_writer (thread_safe_writer &&)=delete | |
| thread_safe_writer & | operator= (thread_safe_writer &&)=delete |
| common::VoidResult | write (const log_entry &entry) final |
| Thread-safe write operation for structured log entries. | |
| common::VoidResult | flush () final |
| Thread-safe flush operation. | |
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 |
| virtual void | set_use_color (bool use_color) |
| Set whether to use color output (if supported) | |
| bool | use_color () const |
| Get current color output setting. | |
| virtual std::string | get_name () const override=0 |
| virtual bool | is_healthy () const override |
| Check if the writer is healthy and operational. | |
| 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. | |
Protected Member Functions | |
| virtual common::VoidResult | write_entry_impl (const log_entry &entry)=0 |
| Implementation of structured write operation (override in derived classes) | |
| virtual common::VoidResult | flush_impl ()=0 |
| Implementation of flush operation (override in derived classes) | |
| std::mutex & | get_mutex () const |
| Access the writer mutex for extended operations. | |
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. | |
Private Attributes | |
| std::mutex | write_mutex_ |
Base class providing automatic thread-safety for writer implementations.
This class uses the Template Method pattern to provide automatic mutex-based synchronization. Public methods acquire a lock and delegate to protected virtual *_impl methods that derived classes override.
Benefits:
Thread-safety guarantees:
Definition at line 81 of file thread_safe_writer.h.
|
explicit |
Constructor with optional formatter.
| formatter | Custom formatter (default: timestamp_formatter) |
Definition at line 10 of file thread_safe_writer.cpp.
|
overridedefault |
Virtual destructor.
|
delete |
|
delete |
|
finalvirtual |
Thread-safe flush operation.
Acquires the mutex and delegates to flush_impl(). This method is final to ensure thread-safety is not bypassed.
Implements kcenon::logger::base_writer.
Definition at line 19 of file thread_safe_writer.cpp.
References flush_impl(), and write_mutex_.

|
protectedpure virtual |
Implementation of flush operation (override in derived classes)
Called by flush() while holding the mutex. Derived classes implement their output-specific flush logic here.
Implemented in counted_console_writer, and memory_writer.
Referenced by flush().

|
inlineprotected |
Access the writer mutex for extended operations.
Allows derived classes to use the same mutex for additional thread-safe operations beyond write/flush. Use with caution to avoid deadlocks.
Definition at line 174 of file thread_safe_writer.h.
Referenced by memory_writer::clear(), counted_console_writer::get_count(), memory_writer::get_entries(), counted_console_writer::print_stats(), memory_writer::size(), and counted_console_writer::total_count().

|
delete |
|
delete |
|
finalvirtual |
Thread-safe write operation for structured log entries.
| entry | The log entry to write (includes structured fields) |
Acquires the mutex and delegates to write_entry_impl(). This method preserves all log entry data including structured fields, OpenTelemetry context, and category information.
Implements kcenon::logger::base_writer.
Definition at line 14 of file thread_safe_writer.cpp.
References write_entry_impl(), and write_mutex_.

|
protectedpure virtual |
Implementation of structured write operation (override in derived classes)
| entry | The log entry to write (includes structured fields) |
Called by write(const log_entry&) while holding the mutex. Derived classes must override this method to implement their output logic.
Implemented in counted_console_writer, and memory_writer.
Referenced by write().

|
mutableprivate |
Mutex for thread-safe write/flush operations
Definition at line 178 of file thread_safe_writer.h.