|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
Abstract base class for all log output writers. More...
#include <base_writer.h>


Public Member Functions | |
| base_writer (std::unique_ptr< log_formatter_interface > formatter=nullptr) | |
| Constructor with optional formatter. | |
| virtual | ~base_writer ()=default |
| common::VoidResult | write (const log_entry &entry) override=0 |
| Write a log entry using the modern interface. | |
| common::VoidResult | flush () override=0 |
| Flush any buffered data. | |
| 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 | |
| std::string | format_log_entry (const log_entry &entry) const |
| Format a log entry using the current formatter. | |
Private Attributes | |
| std::unique_ptr< log_formatter_interface > | formatter_ |
| bool | use_color_ = true |
Abstract base class for all log output writers.
Writers are responsible for outputting log messages to various destinations. This class provides a compatibility layer between the old API and the new interface-based approach, implementing log_writer_interface and IMonitorable for observability (Phase 2.2.5).
Key responsibilities:
Definition at line 95 of file base_writer.h.
|
explicit |
Constructor with optional formatter.
| formatter | Custom formatter (default: timestamp_formatter) |
If no formatter is provided, a default timestamp_formatter is created. This allows writers to use custom formatting strategies while maintaining backward compatibility.
Definition at line 18 of file base_writer.cpp.
References formatter_, and use_color_.
|
virtualdefault |
|
overridepure virtual |
Flush any buffered data.
Forces any buffered log entries to be written to the underlying output destination immediately. This method should be called before program termination or when immediate persistence is required.
Implements kcenon::logger::log_writer_interface.
Implemented in kcenon::logger::async::high_performance_async_writer, kcenon::logger::critical_writer, kcenon::logger::hybrid_writer, kcenon::logger::network_writer, kcenon::logger::otlp_writer, and kcenon::logger::thread_safe_writer.
|
protected |
Format a log entry using the current formatter.
| entry | The log entry to format |
Uses the configured formatter to convert the log entry to a string. This is the recommended method for formatting in derived classes.
Definition at line 35 of file base_writer.cpp.
References formatter_, kcenon::logger::log_entry::message, and kcenon::logger::small_string< SSO_SIZE >::to_string().
Referenced by counted_console_writer::write_entry_impl(), and memory_writer::write_entry_impl().


| log_formatter_interface * kcenon::logger::base_writer::get_formatter | ( | ) | const |
Get the current formatter.
The formatter is immutable after construction for thread safety. To use a different formatter, create a new writer instance.
Definition at line 31 of file base_writer.cpp.
References formatter_.
|
overridepure virtual |
|
inlineoverridevirtual |
Check if the writer is healthy and operational.
Used for health monitoring and automatic failover. A writer might be unhealthy if its destination is unavailable (e.g., disk full, network disconnected).
Implements kcenon::logger::log_writer_interface.
Reimplemented in kcenon::logger::async::high_performance_async_writer, kcenon::logger::critical_writer, kcenon::logger::hybrid_writer, and kcenon::logger::otlp_writer.
Definition at line 207 of file base_writer.h.
|
inlinevirtual |
Set whether to use color output (if supported)
| use_color | true to enable color output, false to disable |
Enables or disables ANSI color codes in formatted output. Only affects writers that output to terminals supporting color.
Reimplemented in kcenon::logger::async::high_performance_async_writer, kcenon::logger::critical_writer, and kcenon::logger::hybrid_writer.
Definition at line 166 of file base_writer.h.
|
inline |
Get current color output setting.
Definition at line 176 of file base_writer.h.
Referenced by kcenon::logger::async::high_performance_async_writer::set_use_color(), kcenon::logger::hybrid_writer::set_use_color(), and counted_console_writer::write_entry_impl().

|
overridepure virtual |
Write a log entry using the modern interface.
| entry | The log entry to write |
This is the primary method that derived classes must implement. It receives a complete log_entry structure with all log information including structured fields, OpenTelemetry context, and category info.
Implements kcenon::logger::log_writer_interface.
Implemented in kcenon::logger::async::high_performance_async_writer, kcenon::logger::critical_writer, kcenon::logger::hybrid_writer, kcenon::logger::network_writer, kcenon::logger::otlp_writer, and kcenon::logger::thread_safe_writer.
|
private |
Current formatter (owns the formatter)
Definition at line 237 of file base_writer.h.
Referenced by base_writer(), format_log_entry(), and get_formatter().
|
private |