sys: Added time and source to logger output

This commit is contained in:
WerWolv
2022-02-02 17:19:50 +01:00
parent c2bcbfb1e0
commit df1d302bcb
10 changed files with 26 additions and 8 deletions

View File

@@ -1,10 +1,22 @@
#pragma once
#include <chrono>
#include <fmt/core.h>
#include <fmt/color.h>
#include <fmt/chrono.h>
namespace hex::log {
namespace {
void printPrefix() {
const auto now = fmt::localtime(std::chrono::system_clock::now());
fmt::print("[{0:%H:%M:%S}] [{1}] ", now, IMHEX_PROJECT_NAME);
}
}
FILE *getDestination();
bool isRedirected();
@@ -15,6 +27,7 @@ namespace hex::log {
template<typename S, typename... Args>
void print(const fmt::text_style &ts, const S &fmt, const Args &...args) {
printPrefix();
if (isRedirected())
fmt::print(getDestination(), fmt::runtime(fmt), args...);
else