Babel  1
The voip software that only works on your local network
Loading...
Searching...
No Matches
Logging::Log Class Reference

A singleton class that provides thread-safe logging capabilities with timestamps, active only when logging 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 logging.
 
void setDebugEnabled (bool enabled)
 Enables or disables debug logging.
 
const bool getLogEnabled () const
 Checks if logging is enabled.
 
const bool getDebugEnabled () const
 Checks if debug logging is enabled.
 
void log (const std::string &message)
 Logs a message if logging is enabled.
 
void log (const char *message)
 Logs a message if logging is enabled.
 
template<typename T >
Logoperator<< (const T &message)
 Appends a message to the log if logging is enabled.
 
Logoperator<< (const std::string &message)
 Appends a string message to the log if logging is enabled.
 
Logoperator<< (std::ostream &(*os)(std::ostream &))
 Handles special stream manipulators (e.g., std::endl) for logging with timestamps if logging is enabled.
 
std::string getCurrentDateTime ()
 Retrieves the current date and time as a formatted string.
 
void setStringAsDebug (const bool stringDebug=false)
 Sets the internal boolean _stringDebug.
 

Static Public Member Functions

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

Detailed Description

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

Definition at line 38 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 137 of file Log.cpp.

◆ getDebugEnabled()

const bool Logging::Log::getDebugEnabled ( ) const

Checks if debug logging is enabled.

Returns
true if debug logging is enabled; false otherwise.

Definition at line 86 of file Log.cpp.

◆ getInstance()

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

Provides access to the singleton instance of the Log class.

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

Definition at line 22 of file Log.cpp.

◆ getLogEnabled()

const bool Logging::Log::getLogEnabled ( ) const

Checks if logging is enabled.

Returns
true if logging is enabled; false otherwise.

Definition at line 76 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 44 of file Log.cpp.

◆ log() [1/2]

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

Logs a message if logging is enabled.

Parameters
messageA C-string containing the message to log.

Definition at line 115 of file Log.cpp.

◆ log() [2/2]

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

Logs a message if logging is enabled.

Parameters
messageThe message to log.

Definition at line 96 of file Log.cpp.

◆ operator<<() [1/3]

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

Appends a string message to the log if logging is enabled.

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

Definition at line 129 of file Log.hpp.

◆ operator<<() [2/3]

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

Appends a message to the log if logging 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 to initialize it outside of the header file or compilation issues will occur.

Definition at line 111 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 logging is enabled.

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

Definition at line 148 of file Log.hpp.

◆ setDebugEnabled()

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

Enables or disables debug logging.

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

Definition at line 66 of file Log.cpp.

◆ setLogEnabled()

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

Enables or disables logging.

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

Definition at line 56 of file Log.cpp.

◆ setStringAsDebug()

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

Sets the internal boolean _stringDebug.

Note
This variable indicates whether the current string is a debug string.
Parameters
stringDebugSet to true if the string is a debug string; false otherwise.

Definition at line 127 of file Log.cpp.


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