Files
stvpn/uxlogger.cpp
T
Олег Бородин 4bed66d2bb working commit
2026-05-19 16:58:44 +02:00

44 lines
1005 B
C++

#include <chrono>
#include <format>
#include <iostream>
#include <mutex>
#include <string>
#include <cstdio>
#include <cstdarg>
#include <uxlogger.hpp>
UxLogger uxlogger;
static std::mutex mtx;
UxLogger::UxLogger(void) {}
void UxLogger::Debug(const std::string& message) {
LogLevel("debug", message);
}
void UxLogger::Info(const std::string& message) {
LogLevel("info", message);
}
void UxLogger::Warning(const std::string& message) {
LogLevel("warning", message);
}
void UxLogger::Error(const std::string& message) {
LogLevel("error", message);
}
void UxLogger::LogLevel(const std::string level, 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, level, message);
}