#include #include #include #include #include "log.h" std::string log_entries; void log(std::string entry, time_t time) { size_t newline_pos; char time_as_str[128] = {0}; strftime(time_as_str, 127 * sizeof(char), "%c", localtime(&time)); while ((newline_pos = entry.find('\n')) != std::string::npos) { entry.replace(newline_pos, 1, 1, ' '); } if (!log_entries.empty()) { log_entries += '\n'; } log_entries += '['; log_entries += time_as_str; log_entries += "] "; log_entries += std::move(entry); } void log(std::string entry) { log(std::move(entry), time(nullptr)); }