cae  0.0.0
Cross-API graphics engine
Loading...
Searching...
No Matches
utl::Logger Class Reference

Class for logging. More...

#include <Logger.hpp>

+ Collaboration diagram for utl::Logger:

Public Member Functions

 Logger (const Logger &)=delete
 
Loggeroperator= (const Logger &)=delete
 
 Logger (Logger &&)=delete
 
Loggeroperator= (Logger &&)=delete
 

Static Public Member Functions

static void init ()
 Initialize the logger.
 
template<typename Func >
static void logExecutionTime (const std::string &message, Func &&func)
 Log the execution time of a function.
 
static void log (const std::string &message, const LogLevel &logLevel)
 Log a message with a specific log level.
 

Private Types

enum class  ColorIndex : uint8_t { COLOR_ERROR = 0 , COLOR_INFO = 1 , COLOR_WARNING = 2 , COLOR_RESET = 3 }
 

Private Member Functions

 Logger ()=default
 
 ~Logger ()=default
 

Static Private Member Functions

template<typename E >
static constexpr auto to_underlying (E e) noexcept
 
static const char * getColorForDuration (const float duration)
 
static std::string formatLogMessage (LogLevel level, const std::string &message)
 

Static Private Attributes

static constexpr std::array< const char *, 4 > LOG_LEVEL_COLOR
 
static constexpr std::array< const char *, 2 > LOG_LEVEL_STRING = {"INFO", "WARNING"}
 

Detailed Description

Class for logging.

Definition at line 28 of file Logger.hpp.

Member Enumeration Documentation

◆ ColorIndex

enum class utl::Logger::ColorIndex : uint8_t
strongprivate
Enumerator
COLOR_ERROR 
COLOR_INFO 
COLOR_WARNING 
COLOR_RESET 

Definition at line 80 of file Logger.hpp.

Constructor & Destructor Documentation

◆ Logger() [1/3]

utl::Logger::Logger ( const Logger & )
delete

◆ Logger() [2/3]

utl::Logger::Logger ( Logger && )
delete

◆ Logger() [3/3]

utl::Logger::Logger ( )
privatedefault

◆ ~Logger()

utl::Logger::~Logger ( )
privatedefault

Member Function Documentation

◆ formatLogMessage()

static std::string utl::Logger::formatLogMessage ( LogLevel level,
const std::string & message )
inlinestaticnodiscardprivate

Definition at line 107 of file Logger.hpp.

References LOG_LEVEL_STRING.

Referenced by log(), and logExecutionTime().

+ Here is the caller graph for this function:

◆ getColorForDuration()

static const char * utl::Logger::getColorForDuration ( const float duration)
inlinestaticnodiscardprivate

Definition at line 100 of file Logger.hpp.

References COLOR_ERROR, COLOR_INFO, COLOR_WARNING, LOG_LEVEL_COLOR, and to_underlying().

Referenced by logExecutionTime().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

void utl::Logger::init ( )
static

Initialize the logger.

Definition at line 7 of file logger.cpp.

Referenced by main().

+ Here is the caller graph for this function:

◆ log()

static void utl::Logger::log ( const std::string & message,
const LogLevel & logLevel )
inlinestatic

Log a message with a specific log level.

Parameters
messageMessage to be logged
logLevelLog level of the message

Definition at line 71 of file Logger.hpp.

References COLOR_INFO, COLOR_RESET, COLOR_WARNING, formatLogMessage(), utl::INFO, LOG_LEVEL_COLOR, and to_underlying().

Referenced by cae::Application::Application(), cae::GLFW::create(), cae::Engine::Engine(), loadPlugins(), main(), cae::Application::parseEngineConf(), printFps(), cae::GLFW::setIcon(), cae::Application::setupEngine(), and cae::Engine::stop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ logExecutionTime()

template<typename Func >
static void utl::Logger::logExecutionTime ( const std::string & message,
Func && func )
inlinestatic

Log the execution time of a function.

Template Parameters
FuncFunction to be measured
Parameters
messageMessage to be logged
funcFunction to be measured

Definition at line 54 of file Logger.hpp.

References COLOR_RESET, formatLogMessage(), getColorForDuration(), utl::INFO, LOG_LEVEL_COLOR, and to_underlying().

+ Here is the call graph for this function:

◆ operator=() [1/2]

Logger & utl::Logger::operator= ( const Logger & )
delete

◆ operator=() [2/2]

Logger & utl::Logger::operator= ( Logger && )
delete

◆ to_underlying()

template<typename E >
static constexpr auto utl::Logger::to_underlying ( E e)
inlinestaticconstexprprivatenoexcept

Definition at line 32 of file Logger.hpp.

Referenced by getColorForDuration(), log(), and logExecutionTime().

+ Here is the caller graph for this function:

Member Data Documentation

◆ LOG_LEVEL_COLOR

std::array<const char *, 4> utl::Logger::LOG_LEVEL_COLOR
staticconstexprprivate
Initial value:
= {
"\033[31m",
"\033[32m",
"\033[33m",
"\033[0m\n"
}

Definition at line 88 of file Logger.hpp.

Referenced by getColorForDuration(), log(), and logExecutionTime().

◆ LOG_LEVEL_STRING

std::array<const char *, 2> utl::Logger::LOG_LEVEL_STRING = {"INFO", "WARNING"}
staticconstexprprivate

Definition at line 95 of file Logger.hpp.

Referenced by formatLogMessage().


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