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

Combines async writer for normal logs with critical_writer for safety. More...

#include <critical_writer.h>

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

Public Member Functions

 hybrid_writer (log_writer_ptr wrapped_writer, critical_writer_config critical_config={}, std::size_t async_queue_size=10000)
 
 ~hybrid_writer () override
 
common::VoidResult write (const log_entry &entry) override
 Write a log entry.
 
common::VoidResult flush () override
 Flush any buffered data.
 
bool is_healthy () const override
 Check if the writer is healthy and operational.
 
std::string get_name () const override
 
void set_use_color (bool use_color) override
 Set whether to use color output (if supported)
 
- 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
 
bool use_color () const
 Get current color output setting.
 
log_formatter_interfaceget_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.
 

Private Attributes

log_writer_ptr critical_writer_
 
std::size_t async_queue_size_
 

Additional Inherited Members

- Static Public Attributes inherited from kcenon::logger::composite_writer_tag
static constexpr writer_category category = writer_category::composite
 
- Static Public Attributes inherited from kcenon::logger::decorator_writer_tag
static constexpr writer_category category = writer_category::decorator
 
- 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.
 

Detailed Description

Combines async writer for normal logs with critical_writer for safety.

This is a convenience class that automatically configures:

  • async_writer for normal/debug/info/warn logs (high performance)
  • Synchronous immediate flush for error/critical/fatal logs (no loss)

Category: Composite (combines async and critical behavior), Decorator

Definition at line 247 of file critical_writer.h.

Constructor & Destructor Documentation

◆ hybrid_writer()

kcenon::logger::hybrid_writer::hybrid_writer ( log_writer_ptr wrapped_writer,
critical_writer_config critical_config = {},
std::size_t async_queue_size = 10000 )
explicit
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/writers/critical_writer.h.

Definition at line 258 of file critical_writer.cpp.

263 : async_queue_size_(async_queue_size)
264{
265 // Wrap in critical_writer first
266 critical_writer_ = std::make_unique<critical_writer>(
267 std::move(wrapped_writer),
268 std::move(critical_config)
269 );
270}

References critical_writer_.

◆ ~hybrid_writer()

kcenon::logger::hybrid_writer::~hybrid_writer ( )
overridedefault

Member Function Documentation

◆ flush()

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

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.

Implements kcenon::logger::base_writer.

Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/writers/critical_writer.h.

Definition at line 279 of file critical_writer.cpp.

279 {
280 return critical_writer_->flush();
281}

References critical_writer_.

◆ get_name()

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

◆ is_healthy()

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

Check if the writer is healthy and operational.

Returns
true if the writer is functioning correctly, false otherwise

Used for health monitoring and automatic failover. A writer might be unhealthy if its destination is unavailable (e.g., disk full, network disconnected).

Note
Default implementation always returns true. Override for writers that can detect failure conditions.
For monitoring integration, use performance_monitor_adapter (Phase 3.3)
Since
1.0.0

Reimplemented from kcenon::logger::base_writer.

Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/writers/critical_writer.h.

Definition at line 283 of file critical_writer.cpp.

283 {
284 return critical_writer_->is_healthy();
285}

References critical_writer_.

◆ set_use_color()

void kcenon::logger::hybrid_writer::set_use_color ( bool use_color)
overridevirtual

Set whether to use color output (if supported)

Parameters
use_colortrue 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.

Note
Has no effect on writers that don't support color (e.g., file writers).
Since
1.0.0

Reimplemented from kcenon::logger::base_writer.

Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/writers/critical_writer.h.

Definition at line 291 of file critical_writer.cpp.

291 {
292 // Color setting is now handled by formatter, not writer interface
293 // This method is kept for backward compatibility but is deprecated
294 (void)use_color; // Suppress unused parameter warning
295}
bool use_color() const
Get current color output setting.

References kcenon::logger::base_writer::use_color().

Here is the call graph for this function:

◆ write()

common::VoidResult kcenon::logger::hybrid_writer::write ( const log_entry & entry)
overridevirtual

Write a log entry.

Parameters
entryThe log entry to write
Returns
common::VoidResult indicating success or error
Since
3.5.0 Changed to use log_entry directly

Implements kcenon::logger::base_writer.

Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/writers/critical_writer.h.

Definition at line 274 of file critical_writer.cpp.

274 {
275 // Critical writer handles both sync (for critical) and async (for normal)
276 return critical_writer_->write(entry);
277}

References critical_writer_.

Member Data Documentation

◆ async_queue_size_

std::size_t kcenon::logger::hybrid_writer::async_queue_size_
private

◆ critical_writer_

log_writer_ptr kcenon::logger::hybrid_writer::critical_writer_
private

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