OpenEnroth 73e68f7
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Logger Class Reference

#include <Logger.h>

Public Member Functions

 Logger (LogLevel level, LogSink *sink)
 
 ~Logger ()
 
bool shouldLog (const LogCategory &category, LogLevel level) const
 
template<class... Args>
void log (const LogCategory &category, LogLevel level, fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void trace (const LogCategory &category, fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void debug (const LogCategory &category, fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void info (const LogCategory &category, fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void warning (const LogCategory &category, fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void error (const LogCategory &category, fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void critical (const LogCategory &category, fmt::format_string< Args... > fmt, Args &&... args)
 
bool shouldLog (LogLevel level) const
 
template<class... Args>
void log (LogLevel level, fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void trace (fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void debug (fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void info (fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void warning (fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void error (fmt::format_string< Args... > fmt, Args &&... args)
 
template<class... Args>
void critical (fmt::format_string< Args... > fmt, Args &&... args)
 
LogLevel level () const
 
void setLevel (LogLevel level)
 
std::optional< LogLevellevel (const LogCategory &category) const
 
void setLevel (LogCategory &category, std::optional< LogLevel > level)
 
LogSinksink () const
 
void setSink (LogSink *sink)
 

Private Member Functions

void logV (const LogCategory &category, LogLevel level, fmt::string_view fmt, fmt::format_args args)
 

Private Attributes

std::mutex _mutex
 
LogCategory _defaultCategory = LogCategory({})
 
LogSink_sink = nullptr
 

Detailed Description

Main logging class.

Logger is a singleton, but the user is supposed to create a Logger instance himself before using it. This would usually be done in the first few lines of main.

Some notes on design decisions:

  1. Logger supports hooking into other logging frameworks, translating the log levels appropriately. Thus, it's possible to create separate LogCategory instances for SDL and FFmpeg logs, and manage log levels through the Logger interface. Setting global log level to LOG_CRITICAL will then prevent both SDL and FFmpeg from emitting any non-critical log messages - the important point being that they will be filtered out at SDL/FFmpeg level, and not in the Logger code.
  2. Point (1) above led to settling on making Logger a singleton. This is what pretty much all other logging libraries do, and thus supporting both multiple Logger instances AND being able to hook into external logging frameworks made very little sense.
  3. This also made it possible to implement log categories efficiently by storing per-category log levels inside the LogCategory objects.
  4. Different logging targets are implemented with the LogSink interface. LogSink also makes it possible to implement complex logging logic, i.e. writing all logs starting with LOG_DEBUG into a file, but printing only errors to the console. It's up to the user to properly implement the log level handling in this case.

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( LogLevel  level,
LogSink sink 
)
explicit

◆ ~Logger()

Logger::~Logger ( )

Member Function Documentation

◆ critical() [1/2]

template<class... Args>
void Logger::critical ( const LogCategory category,
fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ critical() [2/2]

template<class... Args>
void Logger::critical ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ debug() [1/2]

template<class... Args>
void Logger::debug ( const LogCategory category,
fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ debug() [2/2]

template<class... Args>
void Logger::debug ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ error() [1/2]

template<class... Args>
void Logger::error ( const LogCategory category,
fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ error() [2/2]

template<class... Args>
void Logger::error ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ info() [1/2]

template<class... Args>
void Logger::info ( const LogCategory category,
fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ info() [2/2]

template<class... Args>
void Logger::info ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ level() [1/2]

LogLevel Logger::level ( ) const

◆ level() [2/2]

std::optional< LogLevel > Logger::level ( const LogCategory category) const

◆ log() [1/2]

template<class... Args>
void Logger::log ( const LogCategory category,
LogLevel  level,
fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ log() [2/2]

template<class... Args>
void Logger::log ( LogLevel  level,
fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ logV()

void Logger::logV ( const LogCategory category,
LogLevel  level,
fmt::string_view  fmt,
fmt::format_args  args 
)
private

◆ setLevel() [1/2]

void Logger::setLevel ( LogCategory category,
std::optional< LogLevel level 
)

◆ setLevel() [2/2]

void Logger::setLevel ( LogLevel  level)

◆ setSink()

void Logger::setSink ( LogSink sink)

◆ shouldLog() [1/2]

bool Logger::shouldLog ( const LogCategory category,
LogLevel  level 
) const
inline

◆ shouldLog() [2/2]

bool Logger::shouldLog ( LogLevel  level) const
inline

◆ sink()

LogSink * Logger::sink ( ) const

◆ trace() [1/2]

template<class... Args>
void Logger::trace ( const LogCategory category,
fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ trace() [2/2]

template<class... Args>
void Logger::trace ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ warning() [1/2]

template<class... Args>
void Logger::warning ( const LogCategory category,
fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

◆ warning() [2/2]

template<class... Args>
void Logger::warning ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inline

Member Data Documentation

◆ _defaultCategory

LogCategory Logger::_defaultCategory = LogCategory({})
private

◆ _mutex

std::mutex Logger::_mutex
private

◆ _sink

LogSink* Logger::_sink = nullptr
private

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