libdisplaydevice v2026.322.2407
C++ library to modify display devices.
display_device::Logger Class Reference

A singleton class for logging or re-routing logs. More...

#include <src/common/include/display_device/logging.h>

Public Types

using Callback = std::function<void(LogLevel, std::string)>
 Defines the callback type for log data re-routing.
 
enum class  LogLevel {
  verbose = 0 , debug , info , warning ,
  error , fatal
}
 Defines the possible log levels. More...
 

Public Member Functions

bool isLogLevelEnabled (LogLevel log_level) const
 Check if log level is currently enabled.
 
 Logger (Logger const &)=delete
 A deleted copy constructor for singleton pattern.
 
void operator= (Logger const &)=delete
 A deleted assignment operator for singleton pattern.
 
void setCustomCallback (Callback callback)
 Set custom callback for writing the logs.
 
void setLogLevel (LogLevel log_level)
 Set the log level for the logger.
 
void write (LogLevel log_level, std::string value)
 Write the string to the output (via callback) if the log level is enabled.
 

Static Public Member Functions

static Loggerget ()
 Get the singleton instance.
 

Detailed Description

A singleton class for logging or re-routing logs.

This class is not meant to be used directly (only for configuration). Instead, the MACRO below should be used throughout the code for logging.

Note
A lazy-evaluated, correctly-destroyed, thread-safe singleton pattern is used here (https://stackoverflow.com/a/1008289).

Member Enumeration Documentation

◆ LogLevel

Defines the possible log levels.

Note
Level implicitly includes all other levels below it.
All levels are in lower-case on purpose to fit the "BOOST_LOG(info)" style.
Enumerator
verbose 

Verbose level.

debug 

Debug level.

info 

Info level.

warning 

Warning level.

error 

Error level.

fatal 

Fatal level.

Constructor & Destructor Documentation

◆ Logger()

display_device::Logger::Logger ( Logger const & )
delete

A deleted copy constructor for singleton pattern.

Note
Public to ensure better compiler error message.

Member Function Documentation

◆ get()

Logger & display_device::Logger::get ( )
static

Get the singleton instance.

Returns
Singleton instance for the class.

*Examples**

Logger& logger { Logger::get() };
A singleton class for logging or re-routing logs.
Definition logging.h:21
static Logger & get()
Get the singleton instance.
Definition logging.cpp:34

◆ isLogLevelEnabled()

bool display_device::Logger::isLogLevelEnabled ( LogLevel log_level) const
nodiscard

Check if log level is currently enabled.

Parameters
log_levelLog level to check.
Returns
True if log level is enabled.

*Examples**

const bool is_enabled { Logger::get().isLogLevelEnabled(Logger::LogLevel::Info) };
bool isLogLevelEnabled(LogLevel log_level) const
Check if log level is currently enabled.
Definition logging.cpp:43

◆ operator=()

void display_device::Logger::operator= ( Logger const & )
delete

A deleted assignment operator for singleton pattern.

Note
Public to ensure better compiler error message.

◆ setCustomCallback()

void display_device::Logger::setCustomCallback ( Callback callback)

Set custom callback for writing the logs.

Parameters
callbackNew callback to be used or nullptr to reset to the default.

*Examples**

Logger::get().setCustomCallback([](const LogLevel level, std::string value){
// write to file or something
});
LogLevel
Defines the possible log levels.
Definition logging.h:28
void setCustomCallback(Callback callback)
Set custom callback for writing the logs.
Definition logging.cpp:49

◆ setLogLevel()

void display_device::Logger::setLogLevel ( LogLevel log_level)

Set the log level for the logger.

Parameters
log_levelNew level to be used.

*Examples**

Logger::get().setLogLevel(Logger::LogLevel::Info);
void setLogLevel(LogLevel log_level)
Set the log level for the logger.
Definition logging.cpp:39

◆ write()

void display_device::Logger::write ( LogLevel log_level,
std::string value )

Write the string to the output (via callback) if the log level is enabled.

Parameters
log_levelLog level to be checked and (probably) written.
valueA copy of the string to be written.

*Examples**

Logger::get().write(Logger::LogLevel::Info, "Hello World!");
void write(LogLevel log_level, std::string value)
Write the string to the output (via callback) if the log level is enabled.
Definition logging.cpp:53

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