|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
Base interface for all log writers and decorators. More...
#include <log_writer_interface.h>


Public Member Functions | |
| virtual | ~log_writer_interface ()=default |
| virtual common::VoidResult | write (const log_entry &entry)=0 |
| Write a log entry. | |
| virtual common::VoidResult | flush ()=0 |
| Flush any buffered data. | |
| virtual common::VoidResult | close () |
| Close the writer and release resources. | |
| virtual auto | is_open () const -> bool |
| Check if writer is open and ready. | |
| virtual std::string | get_name () const =0 |
| virtual bool | is_healthy () const =0 |
| Check if the writer is healthy. | |
Base interface for all log writers and decorators.
This interface defines the contract for all log writers. It serves as the foundation for the Decorator pattern, enabling composable log writer pipelines where writers can be wrapped with additional functionality (e.g., buffering, encryption, async processing).
Follows the Single Responsibility Principle - only responsible for writing logs. All methods use Result-based error handling for consistent error propagation.
Example: Implementations must override write(), flush(), close(), is_open(), get_name(), and is_healthy() methods. See file_writer or console_writer for concrete examples.
Decorator pattern usage: Writers can be composed by wrapping a base writer with decorators (e.g., buffered_writer wraps base writer, async_writer wraps buffered_writer) to create composable log processing pipelines.
Definition at line 50 of file log_writer_interface.h.
|
virtualdefault |
|
inlinevirtual |
Close the writer and release resources.
Closes the writer, flushing any remaining buffered data and releasing all associated resources (file handles, network connections, etc.). After calling close(), the writer should not be used for further operations.
Default implementation calls flush() and returns success. Subclasses with resources (file handles, connections) should override to release them.
Implemented in kcenon::logger::file_writer.
Definition at line 97 of file log_writer_interface.h.
References flush().
Referenced by kcenon::logger::network_writer::connect(), and kcenon::logger::network_writer::disconnect().


|
pure 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.
Implemented in kcenon::logger::async::high_performance_async_writer, kcenon::logger::async_writer, kcenon::logger::base_writer, kcenon::logger::batch_writer, kcenon::logger::buffered_writer, kcenon::logger::composite_writer, kcenon::logger::console_writer, kcenon::logger::critical_writer, kcenon::logger::decorator_writer_base, kcenon::logger::file_writer, kcenon::logger::hybrid_writer, kcenon::logger::network_writer, kcenon::logger::otlp_writer, and kcenon::logger::thread_safe_writer.
Referenced by close(), kcenon::logger::async_writer::flush(), kcenon::logger::batch_writer::flush_batch_unsafe(), kcenon::logger::buffered_writer::flush_buffer_unsafe(), and kcenon::logger::async_writer::flush_remaining().

|
pure virtual |
Implemented in counted_console_writer, kcenon::logger::async::high_performance_async_writer, kcenon::logger::async_writer, kcenon::logger::base_writer, kcenon::logger::batch_writer, kcenon::logger::composite_writer, kcenon::logger::console_writer, kcenon::logger::critical_writer, kcenon::logger::decorator_writer_base, kcenon::logger::file_writer, kcenon::logger::filtered_writer, kcenon::logger::formatted_writer, kcenon::logger::hybrid_writer, kcenon::logger::network_writer, kcenon::logger::otlp_writer, kcenon::logger::rotating_file_writer, and memory_writer.
Referenced by kcenon::logger::async_writer::get_name(), kcenon::logger::batch_writer::get_name(), kcenon::logger::filtered_writer::get_name(), and kcenon::logger::formatted_writer::get_name().

|
pure virtual |
Check if the writer is healthy.
Returns whether the writer is functioning correctly. Unlike is_open(), this method may perform additional health checks such as verifying disk space, network connectivity, or buffer status.
Implemented in kcenon::logger::async::high_performance_async_writer, kcenon::logger::async_writer, kcenon::logger::base_writer, kcenon::logger::batch_writer, kcenon::logger::composite_writer, kcenon::logger::console_writer, kcenon::logger::critical_writer, kcenon::logger::decorator_writer_base, kcenon::logger::file_writer, kcenon::logger::hybrid_writer, kcenon::logger::otlp_writer, kcenon::logger::queued_writer_base< Container >, kcenon::logger::queued_writer_base< std::queue< log_entry > >, and kcenon::logger::queued_writer_base< std::vector< log_entry > >.
Referenced by kcenon::logger::async_writer::is_healthy(), kcenon::logger::batch_writer::is_healthy(), and kcenon::logger::queued_writer_base< Container >::is_healthy().

|
inlinenodiscardvirtual |
Check if writer is open and ready.
Returns whether the writer is in an operational state. A writer is considered open if:
Default implementation returns true (assumes always open). Subclasses with closeable resources should override to check actual state.
Implemented in kcenon::logger::file_writer.
Definition at line 118 of file log_writer_interface.h.
|
pure virtual |
Write a log entry.
| entry | The log entry to write |
This method should write the provided log entry to the underlying output destination (file, console, network, etc.). The implementation may buffer the data and defer actual I/O until flush() is called.
Implemented in kcenon::logger::async::high_performance_async_writer, kcenon::logger::async_writer, kcenon::logger::base_writer, kcenon::logger::batch_writer, kcenon::logger::buffered_writer, kcenon::logger::composite_writer, kcenon::logger::console_writer, kcenon::logger::critical_writer, kcenon::logger::decorator_writer_base, kcenon::logger::encrypted_writer, kcenon::logger::file_writer, kcenon::logger::filtered_writer, kcenon::logger::formatted_writer, kcenon::logger::hybrid_writer, kcenon::logger::network_writer, kcenon::logger::otlp_writer, kcenon::logger::rotating_file_writer, and kcenon::logger::thread_safe_writer.
Referenced by kcenon::logger::batch_writer::flush_batch_unsafe(), kcenon::logger::buffered_writer::flush_buffer_unsafe(), kcenon::logger::async_writer::flush_remaining(), kcenon::logger::async_writer::process_messages(), kcenon::logger::async_writer::write(), kcenon::logger::filtered_writer::write(), and kcenon::logger::formatted_writer::write().
