From 3c365d65a40c803bdf0eff57707a7c0947a88f2b Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 24 Feb 2024 11:28:47 +0100 Subject: [PATCH] impr: Nicer looking logger output colors --- lib/libimhex/include/hex/helpers/logger.hpp | 20 +++++++++++++++----- lib/libimhex/source/helpers/logger.cpp | 10 ++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/libimhex/include/hex/helpers/logger.hpp b/lib/libimhex/include/hex/helpers/logger.hpp index 83ca8a604..ec3d778fa 100644 --- a/lib/libimhex/include/hex/helpers/logger.hpp +++ b/lib/libimhex/include/hex/helpers/logger.hpp @@ -49,6 +49,16 @@ namespace hex::log { addLogEntry(IMHEX_PROJECT_NAME, level, std::move(message)); } + namespace color { + + fmt::color debug(); + fmt::color info(); + fmt::color warn(); + fmt::color error(); + fmt::color fatal(); + + } + } void suspendLogging(); @@ -56,26 +66,26 @@ namespace hex::log { [[maybe_unused]] void debug(const std::string &fmt, auto && ... args) { #if defined(DEBUG) - hex::log::impl::print(fg(fmt::color::light_green) | fmt::emphasis::bold, "[DEBUG]", fmt, args...); + hex::log::impl::print(fg(impl::color::debug()) | fmt::emphasis::bold, "[DEBUG]", fmt, args...); #else impl::addLogEntry(IMHEX_PROJECT_NAME, "[DEBUG]", fmt::format(fmt::runtime(fmt), args...)); #endif } [[maybe_unused]] void info(const std::string &fmt, auto && ... args) { - hex::log::impl::print(fg(fmt::color::cadet_blue) | fmt::emphasis::bold, "[INFO] ", fmt, args...); + hex::log::impl::print(fg(impl::color::info()) | fmt::emphasis::bold, "[INFO] ", fmt, args...); } [[maybe_unused]] void warn(const std::string &fmt, auto && ... args) { - hex::log::impl::print(fg(fmt::color::orange) | fmt::emphasis::bold, "[WARN] ", fmt, args...); + hex::log::impl::print(fg(impl::color::warn()) | fmt::emphasis::bold, "[WARN] ", fmt, args...); } [[maybe_unused]] void error(const std::string &fmt, auto && ... args) { - hex::log::impl::print(fg(fmt::color::red) | fmt::emphasis::bold, "[ERROR]", fmt, args...); + hex::log::impl::print(fg(impl::color::error()) | fmt::emphasis::bold, "[ERROR]", fmt, args...); } [[maybe_unused]] void fatal(const std::string &fmt, auto && ... args) { - hex::log::impl::print(fg(fmt::color::purple) | fmt::emphasis::bold, "[FATAL]", fmt, args...); + hex::log::impl::print(fg(impl::color::fatal()) | fmt::emphasis::bold, "[FATAL]", fmt, args...); } diff --git a/lib/libimhex/source/helpers/logger.cpp b/lib/libimhex/source/helpers/logger.cpp index 00bfcf50d..fad4421cb 100644 --- a/lib/libimhex/source/helpers/logger.cpp +++ b/lib/libimhex/source/helpers/logger.cpp @@ -131,6 +131,16 @@ namespace hex::log { } } + namespace color { + + fmt::color debug() { return fmt::color::medium_sea_green; } + fmt::color info() { return fmt::color::steel_blue; } + fmt::color warn() { return fmt::color::orange; } + fmt::color error() { return fmt::color::indian_red; } + fmt::color fatal() { return fmt::color::medium_purple; } + + } + } } \ No newline at end of file