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>
|
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 > |
Log & | operator<< (const T &message) |
| Appends a message to the debug log if debugging is enabled.
|
|
Log & | operator<< (const std::string &message) |
| Appends a string message to the debug log if debugging is enabled.
|
|
Log & | operator<< (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 Log & | getInstance (const bool debug=false) |
| Provides access to the singleton instance of the Debug class.
|
|
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.
◆ 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
-
debug | A 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
-
file | The name of the file where the debug information is generated. |
line | The line number where the debug information is generated. |
func | The 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
-
message | A 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
-
message | The 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
-
message | The 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
-
T | The type of the message. |
- Parameters
-
message | The 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
-
os | The 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
-
enabled | Set 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
-
enabled | Set 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
-
Definition at line 59 of file Log.cpp.
The documentation for this class was generated from the following files: