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

Named logger that formats messages and sends them to its sinks; thread-safe. More...

#include <RST/log/Logger.hpp>

Public Member Functions

 Logger (std::string name, LogLevel level=LogLevel::Trace)
 Creates a logger without sinks; add them with addSink().
 
 ~Logger ()
 
 Logger (const Logger &)=delete
 
Logger & operator= (const Logger &)=delete
 
const std::string & getName () const noexcept
 
void setLevel (LogLevel level) noexcept
 Minimum level to log; LogLevel::Off disables the logger.
 
LogLevel getLevel () const noexcept
 
bool shouldLog (LogLevel level) const noexcept
 Whether a message at level would be logged.
 
void flushOn (LogLevel level) noexcept
 Flushes the sinks after every message at level or above.
 
LogLevel getFlushLevel () const noexcept
 
void addSink (std::shared_ptr< ISink > sink)
 
void addSink (std::shared_ptr< ISink > sink, RingBufferSink &history)
 Adds sink after replaying the messages kept by history into it.
 
bool removeSink (const std::shared_ptr< ISink > &sink) noexcept
 Removes sink; returns false if it was not attached.
 
void clearSinks () noexcept
 
std::size_t sinkCount () const noexcept
 
template<class... Args>
void log (LogLevel level, const SourceLocation &source, std::format_string< Args... > format, Args &&... args) noexcept
 Logs a message at level with its source location.
 
void vlog (LogLevel level, const SourceLocation &source, std::string_view category, std::string_view format, std::format_args args) noexcept
 Same as log() with a runtime format string, for wrappers.
 
template<class... Args>
void trace (std::format_string< Args... > format, Args &&... args) noexcept
 Logs at a fixed level: trace(), debug(), info(), warn(), error() and fatal().
 
template<class... Args>
void debug (std::format_string< Args... > format, Args &&... args) noexcept
 
template<class... Args>
void info (std::format_string< Args... > format, Args &&... args) noexcept
 
template<class... Args>
void warn (std::format_string< Args... > format, Args &&... args) noexcept
 
template<class... Args>
void error (std::format_string< Args... > format, Args &&... args) noexcept
 
template<class... Args>
void fatal (std::format_string< Args... > format, Args &&... args) noexcept
 
void log (LogLevel level, std::string_view message, const SourceLocation &source={}) noexcept
 Logs message as is, without formatting.
 
void trace (std::string_view message) noexcept
 
void debug (std::string_view message) noexcept
 
void info (std::string_view message) noexcept
 
void warn (std::string_view message) noexcept
 
void error (std::string_view message) noexcept
 
void fatal (std::string_view message) noexcept
 
void flush () noexcept
 Flushes every sink.
 

Detailed Description

Named logger that formats messages and sends them to its sinks; thread-safe.

Messages use std::format syntax, checked at compile time, and are skipped before any formatting when their level is below getLevel().

Examples
quickstart.cpp.

Constructor & Destructor Documentation

◆ Logger() [1/2]

RST::Log::Logger::Logger ( std::string  name,
LogLevel  level = LogLevel::Trace 
)
explicit

Creates a logger without sinks; add them with addSink().

◆ ~Logger()

RST::Log::Logger::~Logger ( )

◆ Logger() [2/2]

RST::Log::Logger::Logger ( const Logger &  )
delete

Member Function Documentation

◆ operator=()

Logger & RST::Log::Logger::operator= ( const Logger &  )
delete

◆ getName()

const std::string & RST::Log::Logger::getName ( ) const
inlinenoexcept

◆ setLevel()

void RST::Log::Logger::setLevel ( LogLevel  level)
inlinenoexcept

Minimum level to log; LogLevel::Off disables the logger.

Examples
quickstart.cpp.

◆ getLevel()

LogLevel RST::Log::Logger::getLevel ( ) const
inlinenoexcept

◆ shouldLog()

bool RST::Log::Logger::shouldLog ( LogLevel  level) const
inlinenoexcept

Whether a message at level would be logged.

◆ flushOn()

void RST::Log::Logger::flushOn ( LogLevel  level)
inlinenoexcept

Flushes the sinks after every message at level or above.

◆ getFlushLevel()

LogLevel RST::Log::Logger::getFlushLevel ( ) const
inlinenoexcept

◆ addSink() [1/2]

void RST::Log::Logger::addSink ( std::shared_ptr< ISink >  sink)
Examples
quickstart.cpp.

◆ addSink() [2/2]

void RST::Log::Logger::addSink ( std::shared_ptr< ISink >  sink,
RingBufferSink &  history 
)

Adds sink after replaying the messages kept by history into it.

◆ removeSink()

bool RST::Log::Logger::removeSink ( const std::shared_ptr< ISink > &  sink)
noexcept

Removes sink; returns false if it was not attached.

◆ clearSinks()

void RST::Log::Logger::clearSinks ( )
noexcept

◆ sinkCount()

std::size_t RST::Log::Logger::sinkCount ( ) const
noexcept

◆ log() [1/2]

template<class... Args>
void RST::Log::Logger::log ( LogLevel  level,
const SourceLocation &  source,
std::format_string< Args... >  format,
Args &&...  args 
)
inlinenoexcept

Logs a message at level with its source location.

◆ vlog()

void RST::Log::Logger::vlog ( LogLevel  level,
const SourceLocation &  source,
std::string_view  category,
std::string_view  format,
std::format_args  args 
)
noexcept

Same as log() with a runtime format string, for wrappers.

◆ trace() [1/2]

template<class... Args>
void RST::Log::Logger::trace ( std::format_string< Args... >  format,
Args &&...  args 
)
inlinenoexcept

Logs at a fixed level: trace(), debug(), info(), warn(), error() and fatal().

◆ debug() [1/2]

template<class... Args>
void RST::Log::Logger::debug ( std::format_string< Args... >  format,
Args &&...  args 
)
inlinenoexcept
Examples
quickstart.cpp.

◆ info() [1/2]

template<class... Args>
void RST::Log::Logger::info ( std::format_string< Args... >  format,
Args &&...  args 
)
inlinenoexcept
Examples
quickstart.cpp.

◆ warn() [1/2]

template<class... Args>
void RST::Log::Logger::warn ( std::format_string< Args... >  format,
Args &&...  args 
)
inlinenoexcept

◆ error() [1/2]

template<class... Args>
void RST::Log::Logger::error ( std::format_string< Args... >  format,
Args &&...  args 
)
inlinenoexcept

◆ fatal() [1/2]

template<class... Args>
void RST::Log::Logger::fatal ( std::format_string< Args... >  format,
Args &&...  args 
)
inlinenoexcept

◆ log() [2/2]

void RST::Log::Logger::log ( LogLevel  level,
std::string_view  message,
const SourceLocation &  source = {} 
)
noexcept

Logs message as is, without formatting.

◆ trace() [2/2]

void RST::Log::Logger::trace ( std::string_view  message)
inlinenoexcept

◆ debug() [2/2]

void RST::Log::Logger::debug ( std::string_view  message)
inlinenoexcept

◆ info() [2/2]

void RST::Log::Logger::info ( std::string_view  message)
inlinenoexcept

◆ warn() [2/2]

void RST::Log::Logger::warn ( std::string_view  message)
inlinenoexcept

◆ error() [2/2]

void RST::Log::Logger::error ( std::string_view  message)
inlinenoexcept

◆ fatal() [2/2]

void RST::Log::Logger::fatal ( std::string_view  message)
inlinenoexcept

◆ flush()

void RST::Log::Logger::flush ( )
noexcept

Flushes every sink.


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