diff --git a/lib/libimhex/source/helpers/logger.cpp b/lib/libimhex/source/helpers/logger.cpp index 56a6713ca..f69b3dd51 100644 --- a/lib/libimhex/source/helpers/logger.cpp +++ b/lib/libimhex/source/helpers/logger.cpp @@ -15,6 +15,7 @@ namespace hex::log::impl { static wolv::io::File s_loggerFile; + static bool s_colorOutputEnabled = false; std::mutex g_loggerMutex; FILE *getDestination() { @@ -40,11 +41,16 @@ namespace hex::log::impl { s_loggerFile = wolv::io::File(path / hex::format("{0:%Y%m%d_%H%M%S}.log", fmt::localtime(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()))), wolv::io::File::Mode::Create); s_loggerFile.disableBuffering(); - if (s_loggerFile.isValid()) break; + if (s_loggerFile.isValid()) { + s_colorOutputEnabled = true; + break; + } } } void enableColorPrinting() { + s_colorOutputEnabled = true; + #if defined(OS_WINDOWS) auto hConsole = ::GetStdHandle(STD_OUTPUT_HANDLE); if (hConsole != INVALID_HANDLE_VALUE) { @@ -73,10 +79,10 @@ namespace hex::log::impl { fmt::print(dest, "[{0:%H:%M:%S}] ", now); - if (isRedirected()) - fmt::print(dest, "{0} ", level); - else + if (s_colorOutputEnabled) fmt::print(dest, ts, "{0} ", level); + else + fmt::print(dest, "{0} ", level); std::string projectThreadTag = projectName; if (auto threadName = TaskManager::getCurrentThreadName(); !threadName.empty()) diff --git a/main/gui/source/window/linux_window.cpp b/main/gui/source/window/linux_window.cpp index 4518f2913..f6e85c7f4 100644 --- a/main/gui/source/window/linux_window.cpp +++ b/main/gui/source/window/linux_window.cpp @@ -48,6 +48,8 @@ namespace hex { } void Window::initNative() { + log::impl::enableColorPrinting(); + // Add plugin library folders to dll search path for (const auto &path : hex::fs::getDefaultPaths(fs::ImHexPath::Libraries)) { if (std::fs::exists(path)) diff --git a/main/gui/source/window/macos_window.cpp b/main/gui/source/window/macos_window.cpp index 2976d83ba..2fe501839 100644 --- a/main/gui/source/window/macos_window.cpp +++ b/main/gui/source/window/macos_window.cpp @@ -21,6 +21,8 @@ namespace hex { } void Window::initNative() { + log::impl::enableColorPrinting(); + // Add plugin library folders to dll search path for (const auto &path : hex::fs::getDefaultPaths(fs::ImHexPath::Libraries)) { if (std::fs::exists(path))