Motion Master 6.0.0-alpha.50
Next-generation motion control software
Loading...
Searching...
No Matches
mm::RingLogSink< Mutex > Class Template Reference

Thread-safe spdlog sink that retains the most recent log entries in memory. More...

#include <ring_log_sink.h>

Inheritance diagram for mm::RingLogSink< Mutex >:
[legend]
Collaboration diagram for mm::RingLogSink< Mutex >:
[legend]

Public Member Functions

 RingLogSink (std::size_t capacity=100000)
 Constructs the sink with the given ring-buffer capacity.
 
std::vector< std::string > entries ()
 Returns a snapshot of all currently buffered log lines.
 

Protected Member Functions

void sink_it_ (const spdlog::details::log_msg &msg) override
 
void flush_ () override
 

Detailed Description

template<typename Mutex>
class mm::RingLogSink< Mutex >

Thread-safe spdlog sink that retains the most recent log entries in memory.

Stores up to capacity formatted log lines in a ring buffer. Once full the oldest entry is discarded to make room for each new one. entries() returns a snapshot of all buffered lines in chronological order.

Intended use: install alongside the console sink so the HTTP API can serve the in-process log without touching the filesystem.

Template Parameters
MutexMutex type forwarded to spdlog::sinks::base_sink (use std::mutex for multi-threaded sinks).

Constructor & Destructor Documentation

◆ RingLogSink()

template<typename Mutex >
mm::RingLogSink< Mutex >::RingLogSink ( std::size_t  capacity = 100000)
inlineexplicit

Constructs the sink with the given ring-buffer capacity.

Parameters
capacityMaximum number of log lines to retain. Defaults to 10 000.

Member Function Documentation

◆ entries()

template<typename Mutex >
std::vector< std::string > mm::RingLogSink< Mutex >::entries ( )
inline

Returns a snapshot of all currently buffered log lines.

Lines are in chronological order (oldest first). Trailing newlines are stripped so each element is a plain text string suitable for JSON embedding.

Not const because base_sink::mutex_ is not mutable.

Returns
Vector of formatted log lines.

◆ flush_()

template<typename Mutex >
void mm::RingLogSink< Mutex >::flush_ ( )
inlineoverrideprotected

◆ sink_it_()

template<typename Mutex >
void mm::RingLogSink< Mutex >::sink_it_ ( const spdlog::details::log_msg &  msg)
inlineoverrideprotected

The documentation for this class was generated from the following file: