Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
kcenon::logger::log_writer_interface Interface Referenceabstract

Base interface for all log writers and decorators. More...

#include <log_writer_interface.h>

Inheritance diagram for kcenon::logger::log_writer_interface:
Inheritance graph
Collaboration diagram for kcenon::logger::log_writer_interface:
Collaboration graph

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.
 

Detailed Description

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.

Note
Implementations should be thread-safe when used in concurrent contexts.

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.

Since
1.0.0
4.0.0 Added close() and is_open() for Decorator pattern support

Definition at line 50 of file log_writer_interface.h.

Constructor & Destructor Documentation

◆ ~log_writer_interface()

virtual kcenon::logger::log_writer_interface::~log_writer_interface ( )
virtualdefault

Member Function Documentation

◆ close()

virtual common::VoidResult kcenon::logger::log_writer_interface::close ( )
inlinevirtual

Close the writer and release resources.

Returns
common::VoidResult indicating success or failure

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.

Note
Implementations should be idempotent - calling close() multiple times should not cause errors. Subsequent write() calls after close() may fail.

Default implementation calls flush() and returns success. Subclasses with resources (file handles, connections) should override to release them.

Since
4.0.0

Implemented in kcenon::logger::file_writer.

Definition at line 97 of file log_writer_interface.h.

97 {
98 return flush();
99 }
virtual common::VoidResult flush()=0
Flush any buffered data.

References flush().

Referenced by kcenon::logger::network_writer::connect(), and kcenon::logger::network_writer::disconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flush()

virtual common::VoidResult kcenon::logger::log_writer_interface::flush ( )
pure virtual

Flush any buffered data.

Returns
common::VoidResult indicating success or failure

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.

Note
Some writers may perform synchronous I/O in this method, which could block for an extended period.

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().

Here is the caller graph for this function:

◆ get_name()

◆ is_healthy()

virtual bool kcenon::logger::log_writer_interface::is_healthy ( ) const
pure virtual

◆ is_open()

virtual auto kcenon::logger::log_writer_interface::is_open ( ) const -> bool
inlinenodiscardvirtual

Check if writer is open and ready.

Returns
true if the writer is open and ready to accept writes

Returns whether the writer is in an operational state. A writer is considered open if:

  • Resources have been successfully initialized
  • close() has not been called
  • No fatal errors have occurred
Note
This method should be fast and non-blocking.

Default implementation returns true (assumes always open). Subclasses with closeable resources should override to check actual state.

Since
4.0.0

Implemented in kcenon::logger::file_writer.

Definition at line 118 of file log_writer_interface.h.

118 {
119 return true;
120 }

◆ write()

virtual common::VoidResult kcenon::logger::log_writer_interface::write ( const log_entry & entry)
pure virtual

The documentation for this interface was generated from the following file: