R-Type  2
Doom but in better
Loading...
Searching...
No Matches
Logging::Log Class Reference

A singleton class that provides thread-safe logging capabilities with timestamps, active only when loggin and debug outputs only when debugging and logging is enabled. More...

#include <Log.hpp>

Collaboration diagram for Logging::Log:
Collaboration graph

Public Member Functions

std::string getLogLocation (const char *file, int line, const char *func)
 Generates a formatted debug information string with file, line, and function details.
 
void setLogEnabled (bool enabled)
 Enables or disables the logging.
 
void setDebugEnabled (bool enabled)
 Enables or disables the debug logging.
 
void log (const std::string &message)
 Logs a message if debugging is enabled.
 
void log (const char *message)
 Logs a message if debugging is enabled.
 
template<typename T >
Logoperator<< (const T &message)
 Appends a message to the debug log if debugging is enabled.
 
Logoperator<< (const std::string &message)
 Appends a string message to the debug log if debugging is enabled.
 
Logoperator<< (std::ostream &(*os)(std::ostream &))
 Handles special stream manipulators (e.g., std::endl) for logging with timestamps if debugging is enabled.
 
std::string getCurrentDateTime ()
 Retrieves the current date and time as a formatted string.
 
void setStringAsDebug (const bool stringDebug=false)
 Function to set the internal boolean _stringAsDebug.
 

Static Public Member Functions

static LoggetInstance (const bool debug=false)
 Provides access to the singleton instance of the Debug class.
 

Detailed Description

A singleton class that provides thread-safe logging capabilities with timestamps, active only when loggin and debug outputs only when debugging and logging is enabled.

Definition at line 31 of file Log.hpp.

Member Function Documentation

◆ getCurrentDateTime()

std::string Logging::Log::getCurrentDateTime ( )

Retrieves the current date and time as a formatted string.

Returns
The current date and time in "YYYY-MM-DD HH:MM:SS" format.

Definition at line 64 of file Log.cpp.

◆ getInstance()

Logging::Log & Logging::Log::getInstance ( const bool debug = false)
static

Provides access to the singleton instance of the Debug class.

Returns
Reference to the Debug instance.
Parameters
debugA variable to indicate wether the string that is passed is a debug string

Definition at line 16 of file Log.cpp.

◆ getLogLocation()

std::string Logging::Log::getLogLocation ( const char * file,
int line,
const char * func )

Generates a formatted debug information string with file, line, and function details.

Parameters
fileThe name of the file where the debug information is generated.
lineThe line number where the debug information is generated.
funcThe name of the function where the debug information is generated.
Returns
A formatted string containing the debug information.

Definition at line 23 of file Log.cpp.

◆ log() [1/2]

void Logging::Log::log ( const char * message)

Logs a message if debugging is enabled.

Parameters
messageA C-string containing the message to log.

Definition at line 54 of file Log.cpp.

◆ log() [2/2]

void Logging::Log::log ( const std::string & message)

Logs a message if debugging is enabled.

Parameters
messageThe message to log.

Definition at line 40 of file Log.cpp.

◆ operator<<() [1/3]

Log & Logging::Log::operator<< ( const std::string & message)
inline

Appends a string message to the debug log if debugging is enabled.

Parameters
messageThe string message to log.
Returns
Reference to the Log instance for chaining.
Warning
Do not try and initialise it outside of the header file or compilation issues will occur.

Definition at line 112 of file Log.hpp.

◆ operator<<() [2/3]

template<typename T >
Log & Logging::Log::operator<< ( const T & message)
inline

Appends a message to the debug log if debugging is enabled.

Template Parameters
TThe type of the message.
Parameters
messageThe message to log.
Returns
Reference to the Log instance for chaining.
Warning
Do not try and initialise it outside of the header file or compilation issues will occur.

Definition at line 93 of file Log.hpp.

◆ operator<<() [3/3]

Log & Logging::Log::operator<< ( std::ostream &(* os )(std::ostream &))
inline

Handles special stream manipulators (e.g., std::endl) for logging with timestamps if debugging is enabled.

Parameters
osThe stream manipulator to apply.
Returns
Reference to the Log instance for chaining.
Warning
Do not try and initialise it outside of the header file or compilation issues will occur.

Definition at line 132 of file Log.hpp.

◆ setDebugEnabled()

void Logging::Log::setDebugEnabled ( bool enabled)

Enables or disables the debug logging.

Parameters
enabledSet to true to enable debugging; false to disable.

Definition at line 35 of file Log.cpp.

◆ setLogEnabled()

void Logging::Log::setLogEnabled ( bool enabled)

Enables or disables the logging.

Parameters
enabledSet to true to enable debugging; false to disable.

Definition at line 30 of file Log.cpp.

◆ setStringAsDebug()

void Logging::Log::setStringAsDebug ( const bool stringDebug = false)

Function to set the internal boolean _stringAsDebug.

Note
This is the variable in charge of informing the class that the string that is currently provided is a debug string, or not if the value is false.
Parameters
stringDebug

Definition at line 59 of file Log.cpp.


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