Files
ugly/source/log/src/TimestampLog.cpp
2025-07-31 02:09:45 -04:00

24 lines
728 B
C++

#include "TimestampLog.hpp"
#include <format>
#include <chrono>
namespace ugly {
TimestampLog::TimestampLog(std::string_view description, std::ostream &os):
mStartTime{std::chrono::high_resolution_clock::now()},
mrOutputStream{os},
mDescription{description} {}
void TimestampLog::vlog(std::string_view fmt, std::format_args args) {
// Format message as "[123.4567] Name: User Message\n"
using namespace std::chrono;
auto now = high_resolution_clock::now();
auto timestamp = duration_cast<duration<float>>(now - mStartTime).count();
auto message = std::vformat(fmt, args);
mrOutputStream << std::format("[{:9.4f}] {}: {}\n", timestamp, mDescription, message);
}
}