From 90753f4d42eedd2006fa96656b97fba3f04e2098 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 16 Feb 2022 21:31:47 +0100 Subject: [PATCH] sys: Fixed logging to file omitting all tags and new lines --- lib/libimhex/include/hex/helpers/logger.hpp | 22 +++++++++++++------- lib/libimhex/source/api/content_registry.cpp | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/libimhex/include/hex/helpers/logger.hpp b/lib/libimhex/include/hex/helpers/logger.hpp index 6d1ca756c..79cece46c 100644 --- a/lib/libimhex/include/hex/helpers/logger.hpp +++ b/lib/libimhex/include/hex/helpers/logger.hpp @@ -13,18 +13,26 @@ namespace hex::log { namespace { - void printPrefix(const fmt::text_style &ts, const std::string &level) { + void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level) { const auto now = fmt::localtime(std::chrono::system_clock::now()); - fmt::print("[{0:%H:%M:%S}] ", now); - fmt::print(ts, "{0} ", level); - fmt::print("[{0}] ", IMHEX_PROJECT_NAME); + + fmt::print(dest, "[{0:%H:%M:%S}] ", now); + + if (isRedirected()) + fmt::print(dest, "{0} ", level); + else + fmt::print(dest, ts, "{0} ", level); + + fmt::print(dest, "[{0}] ", IMHEX_PROJECT_NAME); } template void print(const fmt::text_style &ts, const std::string &level, const std::string &fmt, auto... args) { - printPrefix(ts, level); - fmt::print(getDestination(), fmt::runtime(fmt), args...); - fmt::print("\n"); + auto dest = getDestination(); + + printPrefix(dest, ts, level); + fmt::print(dest, fmt::runtime(fmt), args...); + fmt::print(dest, "\n"); } } diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index ff3f59c23..4c85b40f5 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -314,7 +314,7 @@ namespace hex { namespace ContentRegistry::DataProcessorNode { void impl::add(const impl::Entry &entry) { - log::info("Registered new data processor node type: [{}]: ", entry.category, entry.name); + log::info("Registered new data processor node type: [{}]: {}", entry.category, entry.name); getEntries().push_back(entry); }