23 lines
668 B
C++
23 lines
668 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) {
|
|
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);
|
|
}
|
|
|
|
}
|