feat: Added --verbose
command line option to enable debug logs
This commit is contained in:
parent
d1a59f8c1b
commit
d4d1acb555
@ -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) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <hex/api/event_manager.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <hex/api/event_manager.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
|
||||
@ -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();
|
||||
|
@ -9,6 +9,7 @@ namespace hex::plugin::builtin {
|
||||
void handleHelpCommand(const std::vector<std::string> &args);
|
||||
void handlePluginsCommand(const std::vector<std::string> &args);
|
||||
void handleLanguageCommand(const std::vector<std::string> &args);
|
||||
void handleVerboseCommand(const std::vector<std::string> &args);
|
||||
|
||||
void handleOpenCommand(const std::vector<std::string> &args);
|
||||
|
||||
|
@ -139,6 +139,10 @@ namespace hex::plugin::builtin {
|
||||
ImHexApi::System::impl::addInitArgument("language", args[0]);
|
||||
}
|
||||
|
||||
void handleVerboseCommand(const std::vector<std::string> &) {
|
||||
hex::log::enableDebugLogging();
|
||||
}
|
||||
|
||||
void handleHashCommand(const std::vector<std::string> &args) {
|
||||
if (args.size() != 2) {
|
||||
hex::log::println("usage: imhex --hash <algorithm> <file>");
|
||||
|
@ -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 },
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user