diff options
Diffstat (limited to 'src/log.cpp')
-rw-r--r-- | src/log.cpp | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/src/log.cpp b/src/log.cpp index 3222c856..f24461cb 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -50,38 +50,39 @@ void Logger::setLogFile(const std::string &logFilename) void Logger::log(const char *log_text, ...) { - if (logFile.is_open()) - { - char* buf = new char[1024]; - va_list ap; - time_t t; + if (!logFile.is_open()) { + return; + } - // Use a temporary buffer to fill in the variables - va_start(ap, log_text); - vsprintf(buf, log_text, ap); - va_end(ap); + char* buf = new char[1024]; + va_list ap; + time_t t; - // Get the current system time - time(&t); + // Use a temporary buffer to fill in the variables + va_start(ap, log_text); + vsprintf(buf, log_text, ap); + va_end(ap); - // Print the log entry - std::stringstream timeStr; - timeStr << "["; - timeStr << ((((t / 60) / 60) % 24 < 10) ? "0" : ""); - timeStr << (int)(((t / 60) / 60) % 24); - timeStr << ":"; - timeStr << (((t / 60) % 60 < 10) ? "0" : ""); - timeStr << (int)((t / 60) % 60); - timeStr << ":"; - timeStr << ((t % 60 < 10) ? "0" : ""); - timeStr << (int)(t % 60); - timeStr << "] "; + // Get the current system time + time(&t); - logFile << timeStr.str() << buf << std::endl; + // Print the log entry + std::stringstream timeStr; + timeStr << "["; + timeStr << ((((t / 60) / 60) % 24 < 10) ? "0" : ""); + timeStr << (int)(((t / 60) / 60) % 24); + timeStr << ":"; + timeStr << (((t / 60) % 60 < 10) ? "0" : ""); + timeStr << (int)((t / 60) % 60); + timeStr << ":"; + timeStr << ((t % 60 < 10) ? "0" : ""); + timeStr << (int)(t % 60); + timeStr << "] "; - // Delete temporary buffer - delete[] buf; - } + logFile << timeStr.str() << buf << std::endl; + + // Delete temporary buffer + delete[] buf; } void Logger::error(const std::string &error_text) |