|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
Decorator that applies a formatter to a wrapped writer. More...
#include <formatted_writer.h>


Public Member Functions | |
| formatted_writer (std::unique_ptr< log_writer_interface > wrapped, std::unique_ptr< log_formatter_interface > formatter) | |
| Construct a formatted writer. | |
| ~formatted_writer () override=default | |
| Destructor. | |
| formatted_writer (const formatted_writer &)=delete | |
| formatted_writer & | operator= (const formatted_writer &)=delete |
| formatted_writer (formatted_writer &&) noexcept=default | |
| formatted_writer & | operator= (formatted_writer &&) noexcept=default |
| common::VoidResult | write (const log_entry &entry) override |
| Write a log entry after applying the formatter. | |
| std::string | get_name () const override |
| Get the name of this writer. | |
| const log_formatter_interface * | get_formatter () const |
| Get the current formatter. | |
Public Member Functions inherited from kcenon::logger::decorator_writer_base | |
| 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_base & | operator= (const decorator_writer_base &)=delete |
| decorator_writer_base (decorator_writer_base &&) noexcept=default | |
| decorator_writer_base & | operator= (decorator_writer_base &&) noexcept=default |
| common::VoidResult | flush () override |
| Flush the wrapped writer. | |
| bool | is_healthy () const override |
| Check if the writer is healthy. | |
| const log_writer_interface * | get_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. | |
Private Attributes | |
| std::unique_ptr< log_formatter_interface > | formatter_ |
Additional Inherited Members | |
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::decorator_writer_base | |
| log_writer_interface & | wrapped () noexcept |
| Access the wrapped writer (non-const) | |
| const log_writer_interface & | wrapped () const noexcept |
| Access the wrapped writer (const) | |
| const std::string & | decorator_name () const noexcept |
| Get the decorator name. | |
Decorator that applies a formatter to a wrapped writer.
This class implements the Decorator pattern for log writers. It wraps any log_writer_interface implementation and applies formatting logic before delegating write operations. The formatted message is stored in the log entry before passing it to the wrapped writer.
Key features:
Category: Synchronous (delegates to wrapped writer), Decorator
Definition at line 71 of file formatted_writer.h.
|
explicit |
Construct a formatted writer.
| wrapped | The writer to wrap with formatting |
| formatter | The formatter to apply before writing |
| std::invalid_argument | if wrapped is nullptr |
Definition at line 13 of file formatted_writer.cpp.
|
overridedefault |
Destructor.
|
delete |
|
defaultnoexcept |
| const log_formatter_interface * kcenon::logger::formatted_writer::get_formatter | ( | ) | const |
Get the current formatter.
Definition at line 50 of file formatted_writer.cpp.
References formatter_.
|
overridevirtual |
Get the name of this writer.
Overrides base class to include formatter name when available.
Reimplemented from kcenon::logger::decorator_writer_base.
Definition at line 42 of file formatted_writer.cpp.
References formatter_, kcenon::logger::decorator_writer_base::get_name(), kcenon::logger::log_writer_interface::get_name(), and kcenon::logger::decorator_writer_base::wrapped().

|
delete |
|
defaultnoexcept |
|
overridevirtual |
Write a log entry after applying the formatter.
| entry | The log entry to write |
If the formatter is nullptr, the entry is delegated directly to the wrapped writer. Otherwise, the formatter is applied to create a formatted message, which is then stored in a new log entry with the same metadata.
Implements kcenon::logger::decorator_writer_base.
Definition at line 19 of file formatted_writer.cpp.
References kcenon::logger::log_entry::category, kcenon::logger::log_entry::fields, formatter_, kcenon::logger::log_entry::level, kcenon::logger::log_entry::location, kcenon::logger::log_entry::otel_ctx, kcenon::logger::log_entry::thread_id, kcenon::logger::log_entry::timestamp, kcenon::logger::decorator_writer_base::wrapped(), and kcenon::logger::log_writer_interface::write().

|
private |
Definition at line 139 of file formatted_writer.h.
Referenced by get_formatter(), get_name(), and write().