diff --git a/lib/libimhex/include/hex/helpers/logger.hpp b/lib/libimhex/include/hex/helpers/logger.hpp index 013128131..245c22aef 100644 --- a/lib/libimhex/include/hex/helpers/logger.hpp +++ b/lib/libimhex/include/hex/helpers/logger.hpp @@ -22,6 +22,7 @@ namespace hex::log { [[nodiscard]] std::recursive_mutex& getLoggerMutex(); [[nodiscard]] bool isLoggingSuspended(); + [[nodiscard]] bool isDebugLoggingEnabled(); struct LogEntry { std::string project; @@ -64,13 +65,14 @@ namespace hex::log { void suspendLogging(); void resumeLogging(); + void enableDebugLogging(); [[maybe_unused]] void debug(const std::string &fmt, auto && ... args) { - #if defined(DEBUG) + if (impl::isDebugLoggingEnabled()) [[unlikely]] { hex::log::impl::print(fg(impl::color::debug()) | fmt::emphasis::bold, "[DEBUG]", fmt, args...); - #else + } else { impl::addLogEntry(IMHEX_PROJECT_NAME, "[DEBUG]", fmt::format(fmt::runtime(fmt), args...)); - #endif + } } [[maybe_unused]] void info(const std::string &fmt, auto && ... args) { diff --git a/lib/libimhex/source/helpers/logger.cpp b/lib/libimhex/source/helpers/logger.cpp index 7abf811e7..023689add 100644 --- a/lib/libimhex/source/helpers/logger.cpp +++ b/lib/libimhex/source/helpers/logger.cpp @@ -1,5 +1,6 @@ -#include #include + +#include #include #include @@ -21,6 +22,7 @@ namespace hex::log { bool s_colorOutputEnabled = false; std::recursive_mutex s_loggerMutex; bool s_loggingSuspended = false; + bool s_debugLoggingEnabled = false; } @@ -32,6 +34,10 @@ namespace hex::log { s_loggingSuspended = false; } + void enableDebugLogging() { + s_debugLoggingEnabled = true; + } + namespace impl { std::recursive_mutex& getLoggerMutex() { @@ -42,6 +48,14 @@ namespace hex::log { return s_loggingSuspended; } + bool isDebugLoggingEnabled() { + #if defined(DEBUG) + return true; + #else + return s_debugLoggingEnabled; + #endif + } + FILE *getDestination() { if (s_loggerFile.isValid()) return s_loggerFile.getHandle(); diff --git a/plugins/builtin/include/content/command_line_interface.hpp b/plugins/builtin/include/content/command_line_interface.hpp index a80245d9d..74f9b3ac2 100644 --- a/plugins/builtin/include/content/command_line_interface.hpp +++ b/plugins/builtin/include/content/command_line_interface.hpp @@ -9,6 +9,7 @@ namespace hex::plugin::builtin { void handleHelpCommand(const std::vector &args); void handlePluginsCommand(const std::vector &args); void handleLanguageCommand(const std::vector &args); + void handleVerboseCommand(const std::vector &args); void handleOpenCommand(const std::vector &args); diff --git a/plugins/builtin/source/content/command_line_interface.cpp b/plugins/builtin/source/content/command_line_interface.cpp index d573f1ce5..815bd675c 100644 --- a/plugins/builtin/source/content/command_line_interface.cpp +++ b/plugins/builtin/source/content/command_line_interface.cpp @@ -139,6 +139,10 @@ namespace hex::plugin::builtin { ImHexApi::System::impl::addInitArgument("language", args[0]); } + void handleVerboseCommand(const std::vector &) { + hex::log::enableDebugLogging(); + } + void handleHashCommand(const std::vector &args) { if (args.size() != 2) { hex::log::println("usage: imhex --hash "); diff --git a/plugins/builtin/source/plugin_builtin.cpp b/plugins/builtin/source/plugin_builtin.cpp index c9f0f9afe..7fd75a996 100644 --- a/plugins/builtin/source/plugin_builtin.cpp +++ b/plugins/builtin/source/plugin_builtin.cpp @@ -61,7 +61,8 @@ IMHEX_PLUGIN_SUBCOMMANDS() { { "help", "Print help about this command", hex::plugin::builtin::handleHelpCommand }, { "version", "Print ImHex version", hex::plugin::builtin::handleVersionCommand }, { "plugins", "Lists all plugins that have been installed", hex::plugin::builtin::handlePluginsCommand }, - { "language", "Changes the language ImHex uses", hex::plugin::builtin::handleLanguageCommand }, + { "language", "Changes the language ImHex uses", hex::plugin::builtin::handleLanguageCommand }, + { "verbose", "Enables verbose debug logging", hex::plugin::builtin::handleVerboseCommand }, { "open", "Open files passed as argument. [default]", hex::plugin::builtin::handleOpenCommand },