|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
Sends logs over network (TCP/UDP) More...
#include <network_writer.h>


Classes | |
| struct | connection_stats |
| Get connection statistics. More... | |
Public Types | |
| enum class | protocol_type { tcp , udp } |
Public Member Functions | |
| network_writer (const std::string &host, uint16_t port, protocol_type protocol=protocol_type::tcp, size_t buffer_size=8192, std::chrono::seconds reconnect_interval=std::chrono::seconds(5)) | |
| Constructor. | |
| ~network_writer () override | |
| Destructor. | |
| common::VoidResult | write (const log_entry &entry) override |
| Write log entry. | |
| common::VoidResult | flush () override |
| Flush pending logs. | |
| std::string | get_name () const override |
| Get writer name. | |
| bool | is_connected () const |
| Check if connected. | |
| connection_stats | get_stats () const |
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 |
| virtual void | set_use_color (bool use_color) |
| Set whether to use color output (if supported) | |
| bool | use_color () const |
| Get current color output setting. | |
| virtual bool | is_healthy () const override |
| Check if the writer is healthy and operational. | |
| 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 | |
| bool | connect () |
| void | disconnect () |
| bool | send_data (const std::string &data) |
| void | process_buffer () |
| void | attempt_reconnect () |
| std::string | format_for_network (const log_entry &entry) |
| std::string | escape_json (const std::string &str) const |
Private Attributes | |
| std::string | host_ |
| uint16_t | port_ |
| protocol_type | protocol_ |
| size_t | buffer_size_ |
| std::chrono::seconds | reconnect_interval_ |
| int | socket_fd_ |
| std::atomic< bool > | connected_ {false} |
| std::atomic< bool > | running_ {false} |
| std::queue< log_entry > | buffer_ |
| std::mutex | buffer_mutex_ |
| std::condition_variable | buffer_cv_ |
| std::unique_ptr< network_send_jthread_worker > | send_worker_ |
| std::unique_ptr< network_reconnect_jthread_worker > | reconnect_worker_ |
| std::mutex | stats_mutex_ |
| connection_stats | stats_ {} |
Additional Inherited Members | |
Static Public Attributes inherited from kcenon::logger::async_writer_tag | |
| static constexpr writer_category | category = writer_category::asynchronous |
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. | |
Sends logs over network (TCP/UDP)
Category: Asynchronous (non-blocking network I/O with background threads)
Definition at line 41 of file network_writer.h.
|
strong |
| kcenon::logger::network_writer::network_writer | ( | const std::string & | host, |
| uint16_t | port, | ||
| protocol_type | protocol = protocol_type::tcp, | ||
| size_t | buffer_size = 8192, | ||
| std::chrono::seconds | reconnect_interval = std::chrono::seconds(5) ) |
Constructor.
| host | Remote host address |
| port | Remote port |
| protocol | Network protocol (TCP/UDP) |
| buffer_size | Internal buffer size |
| reconnect_interval | Reconnection interval in seconds |
Definition at line 198 of file network_writer.cpp.
References attempt_reconnect(), connect(), process_buffer(), protocol_, reconnect_interval_, reconnect_worker_, running_, send_worker_, and tcp.

|
override |
Destructor.
Definition at line 236 of file network_writer.cpp.
References disconnect(), reconnect_worker_, running_, kcenon::logger::utils::safe_destructor_operation(), and send_worker_.

|
private |
Definition at line 435 of file network_writer.cpp.
References connect(), connected_, and running_.
Referenced by network_writer().


|
private |
Definition at line 332 of file network_writer.cpp.
References kcenon::logger::log_writer_interface::close(), connect(), connected_, kcenon::logger::network_writer::connection_stats::connection_failures, host_, kcenon::logger::network_writer::connection_stats::last_connected, kcenon::logger::network_writer::connection_stats::last_error, port_, protocol_, socket_fd_, stats_, stats_mutex_, and tcp.
Referenced by attempt_reconnect(), connect(), and network_writer().


|
private |
Definition at line 381 of file network_writer.cpp.
References kcenon::logger::log_writer_interface::close(), connected_, and socket_fd_.
Referenced by send_data(), and ~network_writer().


|
private |
Definition at line 483 of file network_writer.cpp.
Referenced by format_for_network().

|
overridevirtual |
Flush pending logs.
Implements kcenon::logger::base_writer.
Definition at line 303 of file network_writer.cpp.
References buffer_, buffer_cv_, buffer_mutex_, kcenon::logger::flush_timeout, kcenon::logger::make_logger_void_result(), kcenon::common::ok(), and running_.

|
private |
Definition at line 441 of file network_writer.cpp.
References escape_json(), kcenon::logger::log_entry::level, kcenon::logger::utils::string_utils::level_to_string(), kcenon::logger::log_entry::location, kcenon::logger::log_entry::message, kcenon::logger::log_entry::timestamp, and kcenon::logger::small_string< SSO_SIZE >::to_string().
Referenced by process_buffer().


|
inlineoverridevirtual |
Get writer name.
Implements kcenon::logger::base_writer.
Definition at line 83 of file network_writer.h.
| network_writer::connection_stats kcenon::logger::network_writer::get_stats | ( | ) | const |
Definition at line 327 of file network_writer.cpp.
References stats_, and stats_mutex_.
|
inline |
|
private |
Definition at line 418 of file network_writer.cpp.
References buffer_, buffer_mutex_, format_for_network(), running_, and send_data().
Referenced by network_writer().


|
private |
Definition at line 389 of file network_writer.cpp.
References kcenon::logger::network_writer::connection_stats::bytes_sent, connected_, disconnect(), kcenon::logger::network_writer::connection_stats::last_error, kcenon::logger::network_writer::connection_stats::messages_sent, protocol_, kcenon::logger::network_writer::connection_stats::send_failures, socket_fd_, stats_, stats_mutex_, and tcp.
Referenced by process_buffer().


|
overridevirtual |
Write log entry.
| entry | The log entry to write |
Implements kcenon::logger::base_writer.
Definition at line 268 of file network_writer.cpp.
References buffer_, buffer_mutex_, buffer_size_, kcenon::logger::log_entry::level, kcenon::logger::log_entry::location, kcenon::logger::log_entry::message, kcenon::common::ok(), kcenon::logger::network_writer::connection_stats::send_failures, send_worker_, stats_, stats_mutex_, kcenon::logger::log_entry::timestamp, and kcenon::logger::small_string< SSO_SIZE >::to_string().

|
private |
Definition at line 129 of file network_writer.h.
Referenced by flush(), process_buffer(), and write().
|
private |
Definition at line 131 of file network_writer.h.
Referenced by flush().
|
mutableprivate |
Definition at line 130 of file network_writer.h.
Referenced by flush(), process_buffer(), and write().
|
private |
Definition at line 120 of file network_writer.h.
Referenced by write().
|
private |
Definition at line 125 of file network_writer.h.
Referenced by attempt_reconnect(), connect(), disconnect(), and send_data().
|
private |
Definition at line 117 of file network_writer.h.
Referenced by connect().
|
private |
Definition at line 118 of file network_writer.h.
Referenced by connect().
|
private |
Definition at line 119 of file network_writer.h.
Referenced by connect(), network_writer(), and send_data().
|
private |
Definition at line 121 of file network_writer.h.
Referenced by network_writer().
|
private |
Definition at line 135 of file network_writer.h.
Referenced by network_writer(), and ~network_writer().
|
private |
Definition at line 126 of file network_writer.h.
Referenced by attempt_reconnect(), flush(), network_writer(), process_buffer(), and ~network_writer().
|
private |
Definition at line 134 of file network_writer.h.
Referenced by network_writer(), write(), and ~network_writer().
|
private |
Definition at line 124 of file network_writer.h.
Referenced by connect(), disconnect(), and send_data().
|
private |
Definition at line 139 of file network_writer.h.
Referenced by connect(), get_stats(), send_data(), and write().
|
mutableprivate |
Definition at line 138 of file network_writer.h.
Referenced by connect(), get_stats(), send_data(), and write().