microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
microfmt::log::log_sink Class Reference

Type-erased, two-word handle to a log sink backend, plus the severity threshold below which records are dropped before ever reaching the backend. More...

#include <sink.hpp>

Classes

struct  vtable
 Virtual table of log sink operations. More...
 

Public Member Functions

constexpr log_sink () noexcept=default
 Constructs an empty (invalid) handle.
 
template<typename Tag , typename Traits = log_sink_traits<Tag>, std::enable_if_t< std::is_void_v< typename Traits::context_type >, int > = 0>
constexpr log_sink (Tag, level lvl=level::trace) noexcept
 Constructs a handle for a stateless log sink tag.
 
template<typename Tag , typename Context , typename Traits = log_sink_traits<Tag>, std::enable_if_t<!std::is_void_v< typename Traits::context_type > &&std::is_convertible_v< Context *, typename Traits::context_type * >, int > = 0>
constexpr log_sink (Tag, Context &ctx RELOCO_LIFETIMEBOUND RELOCO_LIFETIME_CAPTURE_BY_THIS, level lvl=level::trace) noexcept
 Constructs a handle for a stateful log sink tag.
 
template<typename Tag , typename Context , std::enable_if_t<!std::is_lvalue_reference_v< Context >, int > = 0>
constexpr log_sink (Tag, Context &&, level=level::trace)=delete
 
void log (const log_msg &msg) noexcept
 Emits msg to the underlying backend, honoring both the record's own level check and this sink's configured threshold.
 
constexpr bool can_flush () const noexcept
 Reports whether the bound backend supports flush.
 
void flush () noexcept
 Flushes buffered output. A no-op when can_flush is false.
 
void set_level (level l) noexcept
 
constexpr bool should_log (level l) const noexcept
 
constexpr operator bool () const noexcept
 Reports whether the handle is bound to a log sink backend.
 

Detailed Description

Type-erased, two-word handle to a log sink backend, plus the severity threshold below which records are dropped before ever reaching the backend.

Packs a context pointer and a vtable pointer into two words: no virtual base class, no RTTI, and no allocation of its own. The bound context (for stateful tags) must outlive every log_sink built from it.

Constructor & Destructor Documentation

◆ log_sink() [1/4]

constexpr microfmt::log::log_sink::log_sink ( )
constexprdefaultnoexcept

Constructs an empty (invalid) handle.

◆ log_sink() [2/4]

template<typename Tag , typename Traits = log_sink_traits<Tag>, std::enable_if_t< std::is_void_v< typename Traits::context_type >, int > = 0>
constexpr microfmt::log::log_sink::log_sink ( Tag  ,
level  lvl = level::trace 
)
inlineexplicitconstexprnoexcept

Constructs a handle for a stateless log sink tag.

Template Parameters
TagLog sink tag type.
TraitsSpecialized traits, enabled when context_type is void.
Parameters
lvlSeverity threshold below which records are dropped.

◆ log_sink() [3/4]

template<typename Tag , typename Context , typename Traits = log_sink_traits<Tag>, std::enable_if_t<!std::is_void_v< typename Traits::context_type > &&std::is_convertible_v< Context *, typename Traits::context_type * >, int > = 0>
constexpr microfmt::log::log_sink::log_sink ( Tag  ,
Context &ctx RELOCO_LIFETIMEBOUND  RELOCO_LIFETIME_CAPTURE_BY_THIS,
level  lvl = level::trace 
)
inlineconstexprnoexcept

Constructs a handle for a stateful log sink tag.

Template Parameters
TagLog sink tag type.
ContextConcrete context type.
TraitsSpecialized traits, enabled when context_type is non-void and Context converts to it.
Parameters
ctxContext object backing the writes.
lvlSeverity threshold below which records are dropped.

◆ log_sink() [4/4]

template<typename Tag , typename Context , std::enable_if_t<!std::is_lvalue_reference_v< Context >, int > = 0>
constexpr microfmt::log::log_sink::log_sink ( Tag  ,
Context &&  ,
level  = level::trace 
)
constexprdelete

Member Function Documentation

◆ can_flush()

constexpr bool microfmt::log::log_sink::can_flush ( ) const
inlineconstexprnoexcept

Reports whether the bound backend supports flush.

◆ flush()

void microfmt::log::log_sink::flush ( )
inlinenoexcept

Flushes buffered output. A no-op when can_flush is false.

◆ log()

void microfmt::log::log_sink::log ( const log_msg &  msg)
inlinenoexcept

Emits msg to the underlying backend, honoring both the record's own level check and this sink's configured threshold.

◆ operator bool()

constexpr microfmt::log::log_sink::operator bool ( ) const
inlineexplicitconstexprnoexcept

Reports whether the handle is bound to a log sink backend.

◆ set_level()

void microfmt::log::log_sink::set_level ( level  l)
inlinenoexcept

◆ should_log()

constexpr bool microfmt::log::log_sink::should_log ( level  l) const
inlineconstexprnoexcept

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