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

Abstract base class for decorator pattern log writers. More...

#include <decorator_writer_base.h>

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

Public Member Functions

 decorator_writer_base (std::unique_ptr< log_writer_interface > wrapped, std::string_view decorator_name)
 Construct a decorator writer base.
 
 ~decorator_writer_base () override=default
 Virtual destructor for proper cleanup.
 
 decorator_writer_base (const decorator_writer_base &)=delete
 
decorator_writer_baseoperator= (const decorator_writer_base &)=delete
 
 decorator_writer_base (decorator_writer_base &&) noexcept=default
 
decorator_writer_baseoperator= (decorator_writer_base &&) noexcept=default
 
common::VoidResult write (const log_entry &entry) override=0
 Write a log entry (must be implemented by derived classes)
 
common::VoidResult flush () override
 Flush the wrapped writer.
 
std::string get_name () const override
 Get the name of this writer.
 
bool is_healthy () const override
 Check if the writer is healthy.
 
const log_writer_interfaceget_wrapped_writer () const noexcept
 Get the wrapped writer (const version)
 
- 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

log_writer_interfacewrapped () noexcept
 Access the wrapped writer (non-const)
 
const log_writer_interfacewrapped () const noexcept
 Access the wrapped writer (const)
 
const std::string & decorator_name () const noexcept
 Get the decorator name.
 

Private Attributes

std::unique_ptr< log_writer_interfacewrapped_
 
std::string decorator_name_
 

Additional Inherited Members

- Static Public Attributes inherited from kcenon::logger::decorator_writer_tag
static constexpr writer_category category = writer_category::decorator
 

Detailed Description

Abstract base class for decorator pattern log writers.

This class provides common functionality for all decorator writers:

  • Wrapped writer storage and lifecycle management
  • Default implementations for get_name(), is_healthy(), and flush()
  • Protected access to wrapped writer for derived classes

Derived classes only need to implement write() with their specific behavior.

Key features:

  • Accepts any log_writer_interface implementation (not just base_writer)
  • Enables unlimited decorator stacking
  • Thread-safety depends on the wrapped writer
  • Follows Liskov Substitution Principle

Category: Decorator (wraps another writer)

Note
This is an abstract class; derived classes must implement write().
Since
4.0.0

Definition at line 71 of file decorator_writer_base.h.

Constructor & Destructor Documentation

◆ decorator_writer_base() [1/3]

kcenon::logger::decorator_writer_base::decorator_writer_base ( std::unique_ptr< log_writer_interface > wrapped,
std::string_view decorator_name )
explicit

Construct a decorator writer base.

Parameters
wrappedThe writer to wrap with this decorator
decorator_nameName prefix for this decorator (e.g., "async", "filtered")
Exceptions
std::invalid_argumentif wrapped is nullptr
Since
4.0.0

Definition at line 18 of file decorator_writer_base.cpp.

21 if (!wrapped_) {
22 throw std::invalid_argument("decorator_writer_base: wrapped writer cannot be nullptr");
23 }
24}
const std::string & decorator_name() const noexcept
Get the decorator name.
std::unique_ptr< log_writer_interface > wrapped_
log_writer_interface & wrapped() noexcept
Access the wrapped writer (non-const)

References wrapped_.

◆ ~decorator_writer_base()

kcenon::logger::decorator_writer_base::~decorator_writer_base ( )
overridedefault

Virtual destructor for proper cleanup.

◆ decorator_writer_base() [2/3]

kcenon::logger::decorator_writer_base::decorator_writer_base ( const decorator_writer_base & )
delete

◆ decorator_writer_base() [3/3]

kcenon::logger::decorator_writer_base::decorator_writer_base ( decorator_writer_base && )
defaultnoexcept

Member Function Documentation

◆ decorator_name()

const std::string & kcenon::logger::decorator_writer_base::decorator_name ( ) const
protectednoexcept

Get the decorator name.

Returns
The decorator name string
Since
4.0.0

Definition at line 50 of file decorator_writer_base.cpp.

50 {
51 return decorator_name_;
52}

References decorator_name_.

◆ flush()

common::VoidResult kcenon::logger::decorator_writer_base::flush ( )
overridevirtual

Flush the wrapped writer.

Returns
common::VoidResult from the wrapped writer's flush operation

Default implementation delegates to wrapped writer. Override if additional flush behavior is needed.

Since
4.0.0

Implements kcenon::logger::log_writer_interface.

Definition at line 26 of file decorator_writer_base.cpp.

26 {
27 return wrapped_->flush();
28}

References wrapped_.

◆ get_name()

std::string kcenon::logger::decorator_writer_base::get_name ( ) const
overridevirtual

Get the name of this writer.

Returns
String in format "<decorator_name>_<wrapped_name>"

Default implementation combines decorator name with wrapped writer's name. Override for custom naming behavior.

Since
4.0.0

Implements kcenon::logger::log_writer_interface.

Reimplemented in kcenon::logger::filtered_writer, and kcenon::logger::formatted_writer.

Examples
decorator_usage.cpp.

Definition at line 30 of file decorator_writer_base.cpp.

30 {
31 return decorator_name_ + "_" + wrapped_->get_name();
32}

References decorator_name_, and wrapped_.

Referenced by example_single_decorators(), kcenon::logger::filtered_writer::get_name(), and kcenon::logger::formatted_writer::get_name().

Here is the caller graph for this function:

◆ get_wrapped_writer()

const log_writer_interface * kcenon::logger::decorator_writer_base::get_wrapped_writer ( ) const
noexcept

Get the wrapped writer (const version)

Returns
Const pointer to the wrapped writer
Since
4.0.0

Definition at line 38 of file decorator_writer_base.cpp.

38 {
39 return wrapped_.get();
40}

References wrapped_.

◆ is_healthy()

bool kcenon::logger::decorator_writer_base::is_healthy ( ) const
overridevirtual

Check if the writer is healthy.

Returns
Health status of the wrapped writer

Default implementation delegates to wrapped writer. Override to add additional health checks.

Since
4.0.0

Implements kcenon::logger::log_writer_interface.

Reimplemented in 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 > >.

Definition at line 34 of file decorator_writer_base.cpp.

34 {
35 return wrapped_->is_healthy();
36}

References wrapped_.

◆ operator=() [1/2]

decorator_writer_base & kcenon::logger::decorator_writer_base::operator= ( const decorator_writer_base & )
delete

◆ operator=() [2/2]

decorator_writer_base & kcenon::logger::decorator_writer_base::operator= ( decorator_writer_base && )
defaultnoexcept

◆ wrapped() [1/2]

const log_writer_interface & kcenon::logger::decorator_writer_base::wrapped ( ) const
protectednoexcept

Access the wrapped writer (const)

Returns
Const reference to the wrapped writer
Since
4.0.0

Definition at line 46 of file decorator_writer_base.cpp.

46 {
47 return *wrapped_;
48}

References wrapped_.

◆ wrapped() [2/2]

◆ write()

common::VoidResult kcenon::logger::decorator_writer_base::write ( const log_entry & entry)
overridepure virtual

Write a log entry (must be implemented by derived classes)

Parameters
entryThe log entry to write
Returns
common::VoidResult indicating success or failure
Since
4.0.0

Implements kcenon::logger::log_writer_interface.

Implemented in kcenon::logger::async_writer, kcenon::logger::batch_writer, kcenon::logger::buffered_writer, kcenon::logger::encrypted_writer, kcenon::logger::filtered_writer, and kcenon::logger::formatted_writer.

Member Data Documentation

◆ decorator_name_

std::string kcenon::logger::decorator_writer_base::decorator_name_
private

Definition at line 186 of file decorator_writer_base.h.

Referenced by decorator_name(), and get_name().

◆ wrapped_

std::unique_ptr<log_writer_interface> kcenon::logger::decorator_writer_base::wrapped_
private

The documentation for this class was generated from the following files: