Implemented logging utilities
This commit is contained in:
18
source/log/src/TimestampLog.cpp
Normal file
18
source/log/src/TimestampLog.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user