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>
|
| 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 > |
| Log & | operator<< (const T &message) |
| | Appends a message to the log if logging is enabled.
|
| |
| Log & | operator<< (const std::string &message) |
| | Appends a string message to the log if logging is enabled.
|
| |
| Log & | operator<< (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 Log & | getInstance (const bool debug=false) |
| | Provides access to the singleton instance of the Log class.
|
| |
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.
◆ 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
-
| debug | A 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
-
| 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 44 of file Log.cpp.
◆ log() [1/2]
| void Logging::Log::log |
( |
const char * | message | ) |
|
Logs a message if logging is enabled.
- Parameters
-
| message | A 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
-
| message | The 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
-
| message | The 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
-
| T | The type of the message. |
- Parameters
-
| message | The 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
-
| os | The 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
-
| enabled | Set 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
-
| enabled | Set 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
-
| stringDebug | Set 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: