2023-01-05 10:27:14 +00:00
|
|
|
#include <ctime>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <exception>
|
|
|
|
#include <system_error>
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
std::string log_entries;
|
|
|
|
|
|
|
|
void log(std::string entry, time_t time) {
|
2023-01-16 03:57:07 +00:00
|
|
|
size_t newline_pos;
|
2023-01-05 10:27:14 +00:00
|
|
|
char time_as_str[128] = {0};
|
|
|
|
|
|
|
|
strftime(time_as_str, 127 * sizeof(char), "%c", localtime(&time));
|
2023-01-16 03:57:07 +00:00
|
|
|
while ((newline_pos = entry.find('\n')) != std::string::npos) {
|
|
|
|
entry.replace(newline_pos, 1, 1, ' ');
|
|
|
|
}
|
2023-01-05 10:27:14 +00:00
|
|
|
|
2023-01-16 03:57:07 +00:00
|
|
|
if (!log_entries.empty()) {
|
|
|
|
log_entries += '\n';
|
|
|
|
}
|
|
|
|
log_entries += '[';
|
|
|
|
log_entries += time_as_str;
|
|
|
|
log_entries += "] ";
|
|
|
|
log_entries += std::move(entry);
|
2023-01-05 10:27:14 +00:00
|
|
|
}
|
|
|
|
|
2023-01-07 09:15:21 +00:00
|
|
|
void log(std::string entry) {
|
2023-01-16 03:59:46 +00:00
|
|
|
log(std::move(entry), time(nullptr));
|
2023-01-07 09:15:21 +00:00
|
|
|
}
|