FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
fastmm::Logger Class Reference

Process-wide registry of per-thread rings + the sink thread. Implemented in log_sink.cpp. More...

#include <fastmm/core/log.hpp>

Public Member Functions

void set_level (LogLevel lvl) noexcept
 
LogLevel level () const noexcept
 
LogRing * attach_current_thread ()
 Gives the calling thread a ring: a drained ring released by an exited thread if one exists, otherwise a new one (heap).
 
void detach_current_thread () noexcept
 Returns the calling thread's ring to the pool.
 
std::size_t thread_slots () const noexcept
 Number of rings allocated so far; reused rings are not counted again.
 
void start (std::FILE *out=stderr, LogLevel mirror_level=LogLevel::Warn)
 Sink control.
 
void stop ()
 drains everything then joins the sink thread
 
void flush ()
 Drains all rings and fflush()es. Works with or without a running sink thread.
 
bool running () const noexcept
 
bool to_file () const noexcept
 The sink writes to a stream other than stderr (a log file).
 
std::uint64_t dropped () const noexcept
 
void note_drop () noexcept
 
std::uint64_t written () const noexcept
 

Static Public Member Functions

static Logger & instance () noexcept
 
static void format_record (const LogRecord &r, std::string &out)
 Formats one record into out (appends). Public for tests/tools.
 

Detailed Description

Process-wide registry of per-thread rings + the sink thread. Implemented in log_sink.cpp.

Member Function Documentation

◆ instance()

static Logger & fastmm::Logger::instance ( )
staticnoexcept

◆ set_level()

void fastmm::Logger::set_level ( LogLevel  lvl)
inlinenoexcept

◆ level()

LogLevel fastmm::Logger::level ( ) const
inlinenoexcept

◆ attach_current_thread()

LogRing * fastmm::Logger::attach_current_thread ( )

Gives the calling thread a ring: a drained ring released by an exited thread if one exists, otherwise a new one (heap).

Call during warm-up on every thread that logs; it is otherwise done lazily on the first log statement. Returns nullptr once kLogMaxThreads rings are in use at the same time.

◆ detach_current_thread()

void fastmm::Logger::detach_current_thread ( )
noexcept

Returns the calling thread's ring to the pool.

Runs automatically when a thread that logged exits, so short-lived threads (sweep workers, Python callers) never exhaust the slots.

◆ thread_slots()

std::size_t fastmm::Logger::thread_slots ( ) const
noexcept

Number of rings allocated so far; reused rings are not counted again.

◆ start()

void fastmm::Logger::start ( std::FILE *  out = stderr,
LogLevel  mirror_level = LogLevel::Warn 
)

Sink control.

out defaults to stderr. Records at >= mirror_level are also copied to stderr when out is a different stream.

◆ stop()

void fastmm::Logger::stop ( )

drains everything then joins the sink thread

◆ flush()

void fastmm::Logger::flush ( )

Drains all rings and fflush()es. Works with or without a running sink thread.

◆ running()

bool fastmm::Logger::running ( ) const
inlinenoexcept

◆ to_file()

bool fastmm::Logger::to_file ( ) const
inlinenoexcept

The sink writes to a stream other than stderr (a log file).

◆ dropped()

std::uint64_t fastmm::Logger::dropped ( ) const
inlinenoexcept

◆ note_drop()

void fastmm::Logger::note_drop ( )
inlinenoexcept

◆ written()

std::uint64_t fastmm::Logger::written ( ) const
inlinenoexcept

◆ format_record()

static void fastmm::Logger::format_record ( const LogRecord &  r,
std::string &  out 
)
static

Formats one record into out (appends). Public for tests/tools.