logmeow/log.cpp

31 lines
675 B
C++
Raw Normal View History

2023-01-05 10:27:14 +00:00
#include <ctime>
#include <string>
#include <vector>
#include <exception>
#include "log.h"
std::string log_entries;
void log(std::string entry, time_t time) {
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));
while ((newline_pos = entry.find('\n')) != std::string::npos) {
entry.replace(newline_pos, 1, 1, ' ');
}
2023-01-05 10:27:14 +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
}