utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
utility::logging::Logger Class Referenceabstract

Abstract logger interface defining stream-style logging operations. More...

#include <headers/utility/logging/logger.hpp>

Inheritance diagram for utility::logging::Logger:

Classes

class  LogMessage
 Proxy object returned by debug/info/warning/error. More...
 

Public Member Functions

 Logger (const std::string &name)
 Default constructor.
 
virtual ~Logger (void)=default
 Virtual destructor for proper cleanup.
 
void setMinLevel (LogLevel level) noexcept
 Set the minimum log level. Messages below this level are suppressed.
 
LogLevel getMinLevel (void) const noexcept
 Get the current minimum log level.
 
void setFlushPolicy (FlushPolicy policy) noexcept
 Set the output flush policy.
 
FlushPolicy getFlushPolicy (void) const noexcept
 Get the current output flush policy.
 
LogMessage debug (std::source_location loc=std::source_location::current())
 Begin a debug-level log message.
 
LogMessage info (std::source_location loc=std::source_location::current())
 Begin an info-level log message.
 
LogMessage warning (std::source_location loc=std::source_location::current())
 Begin a warning-level log message.
 
LogMessage error (std::source_location loc=std::source_location::current())
 Begin an error-level log message.
 
LogMessage log (LogLevel level, std::source_location loc=std::source_location::current())
 Begin a log message with dynamic level.
 
virtual void output (const LogRecord &record)=0
 Output a fully-formed log record.
 
const std::string & getName (void) const
 Get the logger name.
 

Static Public Member Functions

static constexpr LogLevel defaultMinLevel (void) noexcept
 Default minimum level for the current build type.
 
static std::string levelToString (LogLevel level)
 Get string representation of log level.
 
static std::string getTimestamp (void)
 Get current timestamp as formatted string.
 
static constexpr int levelValue (LogLevel level) noexcept
 Get numeric value of a log level for comparison.
 

Protected Attributes

std::mutex _mutex
 Serializes output access.
 

Detailed Description

Abstract logger interface defining stream-style logging operations.

Implementations derive from Logger and override output(const LogRecord&) to handle formatted output.

Definition at line 95 of file logger.hpp.

Constructor & Destructor Documentation

◆ Logger()

utility::logging::Logger::Logger ( const std::string &  name)

Default constructor.

Parameters
nameThe name of the logger.

Definition at line 116 of file logger.cpp.

Member Function Documentation

◆ debug()

LogMessage utility::logging::Logger::debug ( std::source_location  loc = std::source_location::current())
inline

Begin a debug-level log message.

Parameters
locSource location (auto-captured).
Returns
LogMessage proxy for streaming.

Definition at line 336 of file logger.hpp.

Here is the caller graph for this function:

◆ defaultMinLevel()

static constexpr LogLevel utility::logging::Logger::defaultMinLevel ( void  )
inlinestaticconstexprnoexcept

Default minimum level for the current build type.

Release builds (NDEBUG) default to WARNING_LEVEL so hot-loop debug/info calls are suppressed; debug builds keep DEBUG_LEVEL. The UTILITY_LOG_LEVEL environment variable (debug/info/warning/error) overrides this at construction.

Returns
The default minimum level.

Definition at line 255 of file logger.hpp.

◆ error()

LogMessage utility::logging::Logger::error ( std::source_location  loc = std::source_location::current())
inline

Begin an error-level log message.

Parameters
locSource location (auto-captured).
Returns
LogMessage proxy for streaming.

Definition at line 372 of file logger.hpp.

◆ getFlushPolicy()

FlushPolicy utility::logging::Logger::getFlushPolicy ( void  ) const
noexcept

Get the current output flush policy.

Returns
The active flush policy.

Definition at line 144 of file logger.cpp.

Here is the caller graph for this function:

◆ getMinLevel()

LogLevel utility::logging::Logger::getMinLevel ( void  ) const
noexcept

Get the current minimum log level.

Returns
Minimum emitted level.

Definition at line 134 of file logger.cpp.

◆ getName()

const std::string & utility::logging::Logger::getName ( void  ) const
inline

Get the logger name.

Returns
The name of this logger.

Definition at line 401 of file logger.hpp.

Here is the caller graph for this function:

◆ getTimestamp()

std::string utility::logging::Logger::getTimestamp ( void  )
static

Get current timestamp as formatted string.

Returns
Formatted timestamp string.

Definition at line 87 of file logger.cpp.

Here is the caller graph for this function:

◆ info()

LogMessage utility::logging::Logger::info ( std::source_location  loc = std::source_location::current())
inline

Begin an info-level log message.

Parameters
locSource location (auto-captured).
Returns
LogMessage proxy for streaming.

Definition at line 348 of file logger.hpp.

◆ levelToString()

std::string utility::logging::Logger::levelToString ( LogLevel  level)
static

Get string representation of log level.

Parameters
levelThe log level to convert.
Returns
String representation of the level.

Definition at line 71 of file logger.cpp.

Here is the caller graph for this function:

◆ levelValue()

static constexpr int utility::logging::Logger::levelValue ( LogLevel  level)
inlinestaticconstexprnoexcept

Get numeric value of a log level for comparison.

Inline and constexpr so the call-site filter is a single comparison that the optimizer can fold.

Parameters
levelThe log level.
Returns
Integer value (Debug=0, Info=1, Warning=2, Error=3); unknown levels map to a high sentinel so they are never silently dropped.

Definition at line 312 of file logger.hpp.

◆ log()

LogMessage utility::logging::Logger::log ( LogLevel  level,
std::source_location  loc = std::source_location::current() 
)
inline

Begin a log message with dynamic level.

Parameters
levelSeverity level.
locSource location (auto-captured).
Returns
LogMessage proxy for streaming.

Definition at line 385 of file logger.hpp.

◆ output()

virtual void utility::logging::Logger::output ( const LogRecord record)
pure virtual

Output a fully-formed log record.

Parameters
recordThe log record to output.

Implemented in utility::logging::StandardLogger.

Here is the caller graph for this function:

◆ setFlushPolicy()

void utility::logging::Logger::setFlushPolicy ( FlushPolicy  policy)
noexcept

Set the output flush policy.

Parameters
policyThe flush policy to apply.

Definition at line 139 of file logger.cpp.

◆ setMinLevel()

void utility::logging::Logger::setMinLevel ( LogLevel  level)
noexcept

Set the minimum log level. Messages below this level are suppressed.

Parameters
levelMinimum level to emit.

Definition at line 129 of file logger.cpp.

◆ warning()

LogMessage utility::logging::Logger::warning ( std::source_location  loc = std::source_location::current())
inline

Begin a warning-level log message.

Parameters
locSource location (auto-captured).
Returns
LogMessage proxy for streaming.

Definition at line 360 of file logger.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ _mutex

std::mutex utility::logging::Logger::_mutex
mutableprotected

Serializes output access.

Definition at line 122 of file logger.hpp.


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