![]() |
LogIt++
Header-only, macro-first C++ logging library
|
Stores the latest formatted log messages in memory. More...
#include <MemoryLogger.hpp>
Classes | |
| struct | Config |
| Retention limits for the in-memory buffer. More... | |
Public Member Functions | |
| MemoryLogger ()=default | |
| Construct with default retention settings. | |
| MemoryLogger (const Config &config) | |
| Construct with explicit configuration. | |
| MemoryLogger (std::size_t max_records, std::size_t max_bytes, int64_t max_age_ms) | |
| Construct with explicit count/size/age limits. | |
| void | log (const LogRecord &record, const std::string &message) override |
| Store a formatted message in the buffer and evict old entries. | |
| std::string | get_string_param (const LoggerParam ¶m) const override |
| Retrieve legacy string-based metadata. | |
| int64_t | get_int_param (const LoggerParam ¶m) const override |
| Retrieve legacy integer-based metadata. | |
| double | get_float_param (const LoggerParam ¶m) const override |
| Retrieve legacy floating-point metadata. | |
| void | set_log_level (LogLevel level) override |
| Set the minimum accepted log level. | |
| LogLevel | get_log_level () const override |
| Get the minimum accepted log level. | |
| std::vector< std::string > | get_buffered_strings () const override |
| Return buffered formatted strings in chronological order. | |
| std::vector< BufferedLogEntry > | get_buffered_entries () const override |
| Return buffered structured entries in chronological order. | |
| void | wait () override |
| Memory logger is synchronous, so no flush step is needed. | |
| uint64_t | add_log_callback (Callback callback) override |
| Registers a callback to be invoked after each successfully written record. | |
| bool | remove_log_callback (uint64_t callback_id) override |
| Unregisters a previously added callback. | |
| LogClearResult | clear_logs (const LogClearOptions &options=LogClearOptions()) override |
| Clears buffered entries. | |
| std::vector< LogRecordSnapshot > | read_range (int64_t from_ms, int64_t to_ms, std::size_t limit=0) const override |
Reads records in [from_ms, to_ms) ordered by timestamp. | |
| std::vector< LogRecordSnapshot > | read_recent (std::size_t limit, int64_t period_ms=0, LogReadOrder order=LogReadOrder::Ascending) const override |
| Reads the most recent records. | |
Public Member Functions inherited from logit::ILogger | |
| virtual | ~ILogger ()=default |
| virtual std::vector< LogFileInfo > | list_log_files () const |
| Lists persisted log files owned by this backend. | |
| virtual LogFileReadResult | read_log_file (const std::string &path) const |
| Reads one persisted log file owned by this backend. | |
| virtual std::vector< LogFileReadResult > | read_log_files (const std::vector< std::string > &paths) const |
| Reads several persisted log files owned by this backend. | |
| virtual void | shutdown () |
| Stops logger-owned asynchronous resources after draining pending work. | |
Public Member Functions inherited from logit::ILogReader | |
| virtual | ~ILogReader ()=default |
Public Member Functions inherited from logit::ILogSubscriber | |
| virtual | ~ILogSubscriber ()=default |
Private Member Functions | |
| void | notify_callbacks (const LogRecordSnapshot &snapshot) const |
| void | m_pop_front_locked () const |
| void | m_evict_expired_locked (int64_t now_ms) const |
| void | m_enforce_limits_locked (int64_t now_ms) const |
| int64_t | get_last_log_ts () const |
| int64_t | get_time_since_last_log () const |
Static Private Member Functions | |
| static LogRecordSnapshot | to_snapshot (const BufferedLogEntry &e) |
| static std::size_t | m_entry_bytes (const BufferedLogEntry &entry) |
Private Attributes | |
| Config | m_config |
| std::mutex | m_mutex |
| std::deque< BufferedLogEntry > | m_entries |
| std::size_t | m_total_bytes = 0 |
| std::atomic< int64_t > | m_last_log_ts = ATOMIC_VAR_INIT(0) |
| std::atomic< int64_t > | m_last_log_mono_ts = ATOMIC_VAR_INIT(0) |
| std::atomic< int > | m_log_level = ATOMIC_VAR_INIT(static_cast<int>(LogLevel::LOG_LVL_TRACE)) |
| std::mutex | m_callbacks_mutex |
| std::map< uint64_t, Callback > | m_callbacks |
| std::atomic< uint64_t > | m_next_callback_id {1} |
Additional Inherited Members | |
Public Types inherited from logit::ILogSubscriber | |
| using | Callback = std::function<void(const LogRecordSnapshot&)> |
Stores the latest formatted log messages in memory.
Snapshots are returned oldest-to-newest. Read operations avoid Logger-level execution serialization, but still synchronize on this backend's own mutex while copying the current buffer.
Definition at line 22 of file MemoryLogger.hpp.
|
default |
Construct with default retention settings.
|
inlineexplicit |
Construct with explicit configuration.
Definition at line 43 of file MemoryLogger.hpp.
|
inline |
Construct with explicit count/size/age limits.
Definition at line 46 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Registers a callback to be invoked after each successfully written record.
| callback | Function called with the written LogRecordSnapshot. |
Implements logit::ILogSubscriber.
Definition at line 157 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Clears buffered entries.
Implements logit::ILogger.
Definition at line 170 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Return buffered structured entries in chronological order.
Age-based cleanup runs before copying the snapshot.
Implements logit::ILogger.
Definition at line 148 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Return buffered formatted strings in chronological order.
Age-based cleanup runs before copying the snapshot.
Implements logit::ILogger.
Definition at line 134 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Retrieve legacy floating-point metadata.
Implements logit::ILogger.
Definition at line 110 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Retrieve legacy integer-based metadata.
Implements logit::ILogger.
Definition at line 97 of file MemoryLogger.hpp.
|
inlineprivate |
Definition at line 373 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Get the minimum accepted log level.
Implements logit::ILogger.
Definition at line 128 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Retrieve legacy string-based metadata.
Implements logit::ILogger.
Definition at line 84 of file MemoryLogger.hpp.
|
inlineprivate |
Definition at line 377 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Store a formatted message in the buffer and evict old entries.
Implements logit::ILogger.
Definition at line 50 of file MemoryLogger.hpp.
|
inlineprivate |
Definition at line 356 of file MemoryLogger.hpp.
|
inlinestaticprivate |
Definition at line 333 of file MemoryLogger.hpp.
|
inlineprivate |
Definition at line 345 of file MemoryLogger.hpp.
|
inlineprivate |
Definition at line 337 of file MemoryLogger.hpp.
|
inlineprivate |
Definition at line 315 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Reads records in [from_ms, to_ms) ordered by timestamp.
Implements logit::ILogReader.
Definition at line 186 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Reads the most recent records.
Implements logit::ILogReader.
Definition at line 242 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Unregisters a previously added callback.
Removal prevents future dispatch snapshots from including the callback, but cannot cancel an invocation that has already been copied for dispatch.
| callback_id | Id returned by add_log_callback. |
Implements logit::ILogSubscriber.
Definition at line 164 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Set the minimum accepted log level.
Implements logit::ILogger.
Definition at line 123 of file MemoryLogger.hpp.
|
inlinestaticprivate |
Definition at line 304 of file MemoryLogger.hpp.
|
inlineoverridevirtual |
Memory logger is synchronous, so no flush step is needed.
Implements logit::ILogger.
Definition at line 155 of file MemoryLogger.hpp.
|
private |
Definition at line 394 of file MemoryLogger.hpp.
|
mutableprivate |
Definition at line 393 of file MemoryLogger.hpp.
|
private |
Definition at line 386 of file MemoryLogger.hpp.
|
mutableprivate |
Definition at line 388 of file MemoryLogger.hpp.
|
private |
Definition at line 391 of file MemoryLogger.hpp.
|
private |
Definition at line 390 of file MemoryLogger.hpp.
|
private |
Definition at line 392 of file MemoryLogger.hpp.
|
mutableprivate |
Definition at line 387 of file MemoryLogger.hpp.
|
private |
Definition at line 395 of file MemoryLogger.hpp.
|
mutableprivate |
Definition at line 389 of file MemoryLogger.hpp.