working commit

This commit is contained in:
2026-04-25 23:27:32 +02:00
parent ace92da151
commit 43d1cfc2b4
14 changed files with 257 additions and 297 deletions
+45
View File
@@ -0,0 +1,45 @@
#include <chrono>
#include <format>
#include <iostream>
#include <mutex>
#include <string>
#include <cstdio>
#include <cstdarg>
#include <logger.hpp>
Logger logger;
static std::mutex mtx;
Logger::Logger(const std::string ilabel) {
label = ilabel;
}
Logger::Logger(void) {
label = "global";
}
void Logger::Log(const std::string& message) {
auto now = std::chrono::system_clock::now();
std::chrono::zoned_time localnow{std::chrono::current_zone(), now};
std::string timenow = std::format("{:%Y-%m-%dT%H:%M:%OS%Z}", localnow);
std::lock_guard<std::mutex> lock(mtx);
std::cout << std::format("{} {} {}\n", timenow, label, message);
}
void Logger::Logf(const std::string& format, ...) {
auto now = std::chrono::system_clock::now();
std::chrono::zoned_time localnow{std::chrono::current_zone(), now};
std::string timenow = std::format("{:%Y-%m-%dT%H:%M:%OS%Z}", localnow);
std::lock_guard<std::mutex> lock(mtx);
std::printf("%s %s ", timenow.c_str(), label.c_str());
va_list args;
va_start(args, format);
std::vprintf(format.data(), args);
va_end(args);
std::printf("\n");
}