working commit
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user