19 lines
654 B
C++
19 lines
654 B
C++
#include "TimestampLog.hpp"
|
|
|
|
#include <format>
|
|
#include <chrono>
|
|
|
|
|
|
ugly::TimestampLog::TimestampLog(std::ostream &os, std::string_view description):
|
|
mrOutputStream{os},
|
|
mDescription{description},
|
|
mStart{std::chrono::high_resolution_clock::now()} {}
|
|
|
|
|
|
void ugly::TimestampLog::vlog(std::string_view fmt, std::format_args args) {
|
|
auto now = std::chrono::high_resolution_clock::now();
|
|
auto timestamp = std::chrono::duration_cast<std::chrono::duration<float>>(now - mStart).count();
|
|
auto message = std::vformat(fmt, args);
|
|
mrOutputStream << std::format("[{:9.4f}] {}: {}\n", timestamp, mDescription, message);
|
|
}
|