RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
RST::Log::RingBufferSink Class Reference

Keeps the latest messages in memory, to replay them into another sink later. More...

#include <RST/log/Sinks/RingBufferSink.hpp>

Inheritance diagram for RST::Log::RingBufferSink:
RST::Log::ASink RST::Log::ISink

Public Member Functions

 RingBufferSink (std::size_t maxMessages, std::size_t maxBytes=DEFAULT_MAX_BYTES)
 Keeps up to maxMessages messages and about maxBytes bytes, dropping the oldest first.
 
void replayInto (ISink &sink)
 Writes the kept messages into sink, oldest first.
 
std::vector< LogMessageBuffer > snapshot ()
 Copies of the kept messages, oldest first.
 
std::size_t size ()
 
- Public Member Functions inherited from RST::Log::ASink
 ASink ()
 
 ~ASink () override
 
void write (const LogMessage &message) final
 Receives a message from a logger.
 
void flush () final
 
void setLevel (LogLevel level) noexcept final
 Minimum level accepted by this sink.
 
LogLevel getLevel () const noexcept final
 
bool shouldLog (LogLevel level) const noexcept final
 
void setFormatter (std::shared_ptr< Formatter > formatter) final
 Shares a Formatter between sinks.
 
void setPattern (std::string_view pattern) final
 Formats the messages with pattern; see Formatter.
 
- Public Member Functions inherited from RST::Log::ISink
virtual ~ISink ()=default
 

Static Public Attributes

static constexpr std::size_t DEFAULT_MAX_BYTES = 1024 * 1024
 

Protected Member Functions

void log (const LogMessage &message) override
 Writes one message; called with the sink mutex locked.
 
- Protected Member Functions inherited from RST::Log::ASink
virtual void flushSink ()
 Flushes the output; called with the sink mutex locked.
 
std::string_view formatted (const LogMessage &message)
 The message formatted with the sink pattern.
 
std::mutex & sinkMutex () noexcept
 

Detailed Description

Keeps the latest messages in memory, to replay them into another sink later.

Constructor & Destructor Documentation

◆ RingBufferSink()

RST::Log::RingBufferSink::RingBufferSink ( std::size_t  maxMessages,
std::size_t  maxBytes = DEFAULT_MAX_BYTES 
)
explicit

Keeps up to maxMessages messages and about maxBytes bytes, dropping the oldest first.

Member Function Documentation

◆ replayInto()

void RST::Log::RingBufferSink::replayInto ( ISink &  sink)

Writes the kept messages into sink, oldest first.

◆ snapshot()

std::vector< LogMessageBuffer > RST::Log::RingBufferSink::snapshot ( )

Copies of the kept messages, oldest first.

◆ size()

std::size_t RST::Log::RingBufferSink::size ( )

◆ log()

void RST::Log::RingBufferSink::log ( const LogMessage &  message)
overrideprotectedvirtual

Writes one message; called with the sink mutex locked.

Implements RST::Log::ASink.

Member Data Documentation

◆ DEFAULT_MAX_BYTES

constexpr std::size_t RST::Log::RingBufferSink::DEFAULT_MAX_BYTES = 1024 * 1024
staticconstexpr

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