|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
Fluent builder for creating structured log entries. More...
#include <structured_log_builder.h>

Public Types | |
| using | emit_callback = std::function<void(log_entry&&)> |
| Callback type for emitting structured log entries. | |
Public Member Functions | |
| structured_log_builder (log_level level, emit_callback callback, const log_fields *context_fields=nullptr) | |
| Constructor. | |
| structured_log_builder & | message (const std::string &msg) |
| Set the log message. | |
| structured_log_builder & | field (const std::string &key, const std::string &value) |
| Add a string field. | |
| structured_log_builder & | field (const std::string &key, const char *value) |
| Add a C-string field. | |
| structured_log_builder & | field (const std::string &key, int value) |
| Add an integer field. | |
| structured_log_builder & | field (const std::string &key, int64_t value) |
| Add a long integer field. | |
| structured_log_builder & | field (const std::string &key, double value) |
| Add a double field. | |
| structured_log_builder & | field (const std::string &key, bool value) |
| Add a boolean field. | |
| structured_log_builder & | field (const std::string &key, const log_value &value) |
| Add a log_value field. | |
| structured_log_builder & | category (const std::string &cat) |
| Set the category for the log entry. | |
| void | emit () |
| Emit the log entry. | |
| ~structured_log_builder ()=default | |
| Destructor - does NOT auto-emit. | |
| structured_log_builder (const structured_log_builder &)=delete | |
| structured_log_builder & | operator= (const structured_log_builder &)=delete |
| structured_log_builder (structured_log_builder &&) noexcept=default | |
| structured_log_builder & | operator= (structured_log_builder &&) noexcept=default |
Private Attributes | |
| log_level | level_ |
| emit_callback | callback_ |
| std::string | message_ |
| std::string | category_ |
| log_fields | fields_ |
Fluent builder for creating structured log entries.
Provides a builder pattern for constructing log entries with arbitrary structured fields. The builder collects message and field information, then emits the log entry when emit() is called.
Thread-safety: Each builder instance should be used by a single thread. The emit() operation is thread-safe.
Definition at line 57 of file structured_log_builder.h.
| using kcenon::logger::structured_log_builder::emit_callback = std::function<void(log_entry&&)> |
Callback type for emitting structured log entries.
Definition at line 62 of file structured_log_builder.h.
|
inline |
Constructor.
| level | Log level for the entry |
| callback | Callback to invoke when emit() is called |
| context_fields | Context fields to include automatically |
Definition at line 70 of file structured_log_builder.h.
|
default |
Destructor - does NOT auto-emit.
If emit() was not called, the log entry is discarded. This is intentional to avoid unexpected behavior.
|
delete |
|
defaultnoexcept |
|
inline |
Set the category for the log entry.
| cat | Category string |
Definition at line 172 of file structured_log_builder.h.
References category_.
|
inline |
Emit the log entry.
Constructs the log_entry with all accumulated fields and invokes the callback to send it to the logger. After calling emit(), the builder should not be reused.
Definition at line 184 of file structured_log_builder.h.
References callback_, kcenon::logger::log_entry::category, category_, kcenon::logger::log_entry::fields, fields_, level_, and message_.
|
inline |
Add a boolean field.
| key | Field name |
| value | Field value |
Definition at line 151 of file structured_log_builder.h.
References fields_.
|
inline |
Add a C-string field.
| key | Field name |
| value | Field value |
Definition at line 107 of file structured_log_builder.h.
References fields_.
|
inline |
Add a log_value field.
| key | Field name |
| value | Field value |
Definition at line 162 of file structured_log_builder.h.
References fields_.
|
inline |
Add a string field.
| key | Field name |
| value | Field value |
Definition at line 96 of file structured_log_builder.h.
References fields_.
|
inline |
Add a double field.
| key | Field name |
| value | Field value |
Definition at line 140 of file structured_log_builder.h.
References fields_.
|
inline |
Add an integer field.
| key | Field name |
| value | Field value |
Definition at line 118 of file structured_log_builder.h.
References fields_.
|
inline |
Add a long integer field.
| key | Field name |
| value | Field value |
Definition at line 129 of file structured_log_builder.h.
References fields_.
|
inline |
Set the log message.
| msg | The message to log |
Definition at line 85 of file structured_log_builder.h.
References message_.
|
delete |
|
defaultnoexcept |
|
private |
Definition at line 220 of file structured_log_builder.h.
Referenced by emit().
|
private |
Definition at line 222 of file structured_log_builder.h.
Referenced by category(), and emit().
|
private |
|
private |
Definition at line 219 of file structured_log_builder.h.
Referenced by emit().
|
private |
Definition at line 221 of file structured_log_builder.h.