26 std::ios_base::sync_with_stdio(
false);
34Logging::Log::Log() : _debugEnabled(false) {}
46 std::ostringstream oss;
47 oss << file <<
":" << line <<
" " << func <<
"()";
58 _logEnabled = enabled;
68 _debugEnabled = enabled;
102 if (_stringDebug && !_debugEnabled) {
106 std::lock_guard<std::mutex> lock(_mtxLog);
107 std::cout << getCurrentDateTime() << message << std::endl;
117 log(std::string(message));
129 _stringDebug = stringDebug;
139 auto now = std::chrono::system_clock::now();
140 std::time_t currentTime = std::chrono::system_clock::to_time_t(now);
141 auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(
142 now.time_since_epoch()
145 std::tm *tm = std::localtime(¤tTime);
147 std::stringstream ss;
148 ss <<
"[" << (tm->tm_year + 1900) <<
"-"
149 << (tm->tm_mon + 1) <<
"-"
150 << tm->tm_mday <<
" "
151 << tm->tm_hour <<
":"
154 << std::setfill(
'0') << std::setw(3) << millis <<
"]";
This file contains the Log class responsible for outputting information only when requested.
A singleton class that provides thread-safe logging capabilities with timestamps, active only when lo...
void log(const std::string &message)
Logs a message if logging is enabled.
void setStringAsDebug(const bool stringDebug=false)
Sets the internal boolean _stringDebug.
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.
static Log & getInstance(const bool debug=false)
Provides access to the singleton instance of the Log class.
const bool getDebugEnabled() const
Checks if debug logging is enabled.
void setDebugEnabled(bool enabled)
Enables or disables debug logging.
std::string getCurrentDateTime()
Retrieves the current date and time as a formatted string.
const bool getLogEnabled() const
Checks if logging is enabled.