|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
High-performance asynchronous writer. More...
#include <high_performance_async_writer.h>


Classes | |
| struct | config |
| Configuration for the high-performance async writer. More... | |
| struct | performance_stats |
| Performance statistics. More... | |
| struct | queued_log_entry |
| Log entry optimized for high-performance queuing. More... | |
Public Member Functions | |
| high_performance_async_writer (log_writer_ptr wrapped_writer, const config &cfg=config{}) | |
| Constructor. | |
| ~high_performance_async_writer () override | |
| Destructor. | |
| bool | start () |
| Start the async writer. | |
| void | stop (bool flush_remaining=true) |
| Stop the async writer. | |
| common::VoidResult | write (const log_entry &entry) override |
| Write a log entry asynchronously. | |
| common::VoidResult | flush () override |
| Flush all pending messages. | |
| bool | is_healthy () const override |
| Check if the writer is healthy. | |
| std::string | get_name () const override |
| Get the name of this writer. | |
| void | set_use_color (bool use_color) override |
| Set whether to use color output. | |
| const performance_stats & | get_stats () const |
| Get performance statistics. | |
| void | reset_stats () |
| Reset performance statistics. | |
| double | get_queue_utilization () const |
| Get current queue utilization. | |
| const batch_processor::processing_stats * | get_batch_stats () const |
| Get batch processor statistics if enabled. | |
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_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. | |
Private Member Functions | |
| common::VoidResult | write_direct (const log_entry &entry) |
| Write directly to the underlying writer (fallback mode) | |
| void | update_stats (bool success, std::chrono::nanoseconds latency) |
| Update performance statistics. | |
| batch_processor::batch_entry | to_batch_entry (const queued_log_entry &entry) const |
| Convert to batch entry format. | |
Private Attributes | |
| config | config_ |
| log_writer_ptr | wrapped_writer_ |
| std::unique_ptr< batch_processor > | batch_processor_ |
| std::unique_ptr< memory::object_pool< memory::log_entry_pool::pooled_log_entry > > | memory_pool_ |
| std::atomic< bool > | running_ {false} |
| performance_stats | stats_ |
Additional Inherited Members | |
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. | |
High-performance asynchronous writer.
This writer combines lock-free queuing, memory pooling, and batch processing to achieve maximum throughput while maintaining low latency.
Definition at line 36 of file high_performance_async_writer.h.
|
explicit |
Constructor.
| wrapped_writer | The underlying writer to wrap |
| cfg | Configuration |
Definition at line 10 of file high_performance_async_writer.cpp.
References config_, kcenon::logger::async::high_performance_async_writer::config::enable_batch_processing, kcenon::logger::async::high_performance_async_writer::config::enable_memory_pooling, and wrapped_writer_.
|
override |
Destructor.
Definition at line 34 of file high_performance_async_writer.cpp.
References stop().

|
overridevirtual |
Flush all pending messages.
Implements kcenon::logger::base_writer.
Definition at line 103 of file high_performance_async_writer.cpp.
References batch_processor_, kcenon::common::ok(), and wrapped_writer_.

| const batch_processor::processing_stats * kcenon::logger::async::high_performance_async_writer::get_batch_stats | ( | ) | const |
Get batch processor statistics if enabled.
Definition at line 144 of file high_performance_async_writer.cpp.
References batch_processor_.
|
overridevirtual |
Get the name of this writer.
Implements kcenon::logger::base_writer.
Definition at line 124 of file high_performance_async_writer.cpp.
References wrapped_writer_.
| double kcenon::logger::async::high_performance_async_writer::get_queue_utilization | ( | ) | const |
Get current queue utilization.
Definition at line 135 of file high_performance_async_writer.cpp.
References batch_processor_, config_, and kcenon::logger::async::high_performance_async_writer::config::queue_size.
|
inline |
Get performance statistics.
Definition at line 165 of file high_performance_async_writer.h.
References stats_.
|
overridevirtual |
Check if the writer is healthy.
Reimplemented from kcenon::logger::base_writer.
Definition at line 112 of file high_performance_async_writer.cpp.
References batch_processor_, running_, and wrapped_writer_.
|
inline |
Reset performance statistics.
Definition at line 170 of file high_performance_async_writer.h.
References kcenon::logger::async::high_performance_async_writer::performance_stats::reset(), and stats_.

|
overridevirtual |
Set whether to use color output.
| use_color | Enable/disable color output |
Reimplemented from kcenon::logger::base_writer.
Definition at line 129 of file high_performance_async_writer.cpp.
References kcenon::logger::base_writer::use_color().

| bool kcenon::logger::async::high_performance_async_writer::start | ( | ) |
Start the async writer.
Definition at line 38 of file high_performance_async_writer.cpp.
References batch_processor_, and running_.
| void kcenon::logger::async::high_performance_async_writer::stop | ( | bool | flush_remaining = true | ) |
Stop the async writer.
| flush_remaining | Whether to flush remaining messages |
Definition at line 51 of file high_performance_async_writer.cpp.
References batch_processor_, running_, and wrapped_writer_.
Referenced by ~high_performance_async_writer().

|
private |
Convert to batch entry format.
Definition at line 189 of file high_performance_async_writer.cpp.
References kcenon::logger::async::high_performance_async_writer::queued_log_entry::file, kcenon::logger::async::high_performance_async_writer::queued_log_entry::function, kcenon::logger::async::high_performance_async_writer::queued_log_entry::level, kcenon::logger::async::high_performance_async_writer::queued_log_entry::line, kcenon::logger::async::high_performance_async_writer::queued_log_entry::message, and kcenon::logger::async::high_performance_async_writer::queued_log_entry::timestamp.
|
private |
Update performance statistics.
Definition at line 167 of file high_performance_async_writer.cpp.
References kcenon::logger::async::high_performance_async_writer::performance_stats::average_latency_us, kcenon::logger::async::high_performance_async_writer::performance_stats::start_time, stats_, kcenon::logger::success, kcenon::logger::async::high_performance_async_writer::performance_stats::successful_writes, kcenon::logger::async::high_performance_async_writer::performance_stats::throughput_per_second, and kcenon::logger::async::high_performance_async_writer::performance_stats::total_writes.
Referenced by write(), and write_direct().

|
overridevirtual |
Write a log entry asynchronously.
| entry | The log entry to write |
Implements kcenon::logger::base_writer.
Definition at line 63 of file high_performance_async_writer.cpp.
References batch_processor_, kcenon::logger::async::high_performance_async_writer::performance_stats::dropped_writes, kcenon::logger::log_entry::level, kcenon::logger::log_entry::location, kcenon::logger::log_entry::message, kcenon::common::ok(), running_, stats_, kcenon::logger::log_entry::timestamp, kcenon::logger::small_string< SSO_SIZE >::to_string(), kcenon::logger::async::high_performance_async_writer::performance_stats::total_writes, update_stats(), and write_direct().

|
private |
Write directly to the underlying writer (fallback mode)
Definition at line 151 of file high_performance_async_writer.cpp.
References kcenon::logger::make_logger_void_result(), update_stats(), wrapped_writer_, and kcenon::logger::writer_not_available.
Referenced by write().


|
private |
Definition at line 236 of file high_performance_async_writer.h.
Referenced by flush(), get_batch_stats(), get_queue_utilization(), is_healthy(), start(), stop(), and write().
|
private |
Definition at line 230 of file high_performance_async_writer.h.
Referenced by get_queue_utilization(), and high_performance_async_writer().
|
private |
Definition at line 237 of file high_performance_async_writer.h.
|
private |
Definition at line 240 of file high_performance_async_writer.h.
Referenced by is_healthy(), start(), stop(), and write().
|
mutableprivate |
Definition at line 243 of file high_performance_async_writer.h.
Referenced by get_stats(), reset_stats(), update_stats(), and write().
|
private |
Definition at line 233 of file high_performance_async_writer.h.
Referenced by flush(), get_name(), high_performance_async_writer(), is_healthy(), stop(), and write_direct().