Made the timezone abbreviation static in the Logger, as it will rarely change throughout an execution cycle and was surprisingly resulting in too many memory allocations.

This commit is contained in:
Nav
2021-08-19 22:09:11 +01:00
parent 3554960a19
commit 682de0a2ad

View File

@@ -9,12 +9,12 @@ void Logger::log(const std::string& message, LogLevel logLevel, bool print) {
auto logEntry = LogEntry(message, logLevel); auto logEntry = LogEntry(message, logLevel);
Logger::logEntries.push_back(logEntry); Logger::logEntries.push_back(logEntry);
auto index = Logger::logEntries.size(); auto index = Logger::logEntries.size();
static auto timezoneAbbreviation = DateTime::getTimeZoneAbbreviation(logEntry.timestamp).toStdString();
if (print) { if (print) {
// Print the timestamp and index in a green font color: // Print the timestamp and index in a green font color:
std::cout << "\033[32m"; std::cout << "\033[32m";
std::cout << logEntry.timestamp.toString("yyyy-MM-dd hh:mm:ss ").toStdString() + std::cout << logEntry.timestamp.toString("yyyy-MM-dd hh:mm:ss ").toStdString() + timezoneAbbreviation;
DateTime::getTimeZoneAbbreviation(logEntry.timestamp).toStdString();
if (!logEntry.threadName.empty()) { if (!logEntry.threadName.empty()) {
std::cout << " [" << logEntry.threadName << "]"; std::cout << " [" << logEntry.threadName << "]";