diff --git a/src/helpers/Log.hpp b/src/helpers/Log.hpp index 357f4f5..00770da 100644 --- a/src/helpers/Log.hpp +++ b/src/helpers/Log.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include #include +#include enum eLogLevel { TRACE = 0, @@ -24,6 +24,17 @@ enum eLogLevel { #define ASSERT(expr) RASSERT(expr, "?") namespace Debug { + constexpr const char* logLevelString(eLogLevel level) { + switch (level) { + case TRACE: return "TRACE"; break; + case INFO: return "INFO"; break; + case LOG: return "LOG"; break; + case WARN: return "WARN"; break; + case ERR: return "ERR"; break; + case CRIT: return "CRITICAL"; break; + default: return "??"; + } + } inline bool quiet = false; inline bool verbose = false; @@ -37,21 +48,7 @@ namespace Debug { return; if (level != NONE) { - std::cout << '['; - - switch (level) { - case TRACE: std::cout << "TRACE"; break; - case INFO: std::cout << "INFO"; break; - case LOG: std::cout << "LOG"; break; - case WARN: std::cout << "WARN"; break; - case ERR: std::cout << "ERR"; break; - case CRIT: std::cout << "CRITICAL"; break; - default: break; - } - - std::cout << "] "; + std::println("[{}] {}", logLevelString(level), std::vformat(fmt, std::make_format_args(args...))); } - - std::cout << std::vformat(fmt, std::make_format_args(args...)) << std::endl; } }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index a4572ab..156c580 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,13 @@ #include "config/ConfigManager.hpp" #include "core/hyprlock.hpp" -#include "src/helpers/Log.hpp" +#include "helpers/Log.hpp" #include #include #include void help() { - std::cout << "Usage: hyprlock [options]\n\n" + std::println("Usage: hyprlock [options]\n\n" "Options:\n" " -v, --verbose - Enable verbose logging\n" " -q, --quiet - Disable logging\n" @@ -17,14 +17,14 @@ void help() { " --immediate-render - Do not wait for resources before drawing the background\n" " --no-fade-in - Disable the fade-in animation when the lock screen appears\n" " -V, --version - Show version information\n" - " -h, --help - Show this help message\n"; + " -h, --help - Show this help message"); } std::optional parseArg(const std::vector& args, const std::string& flag, std::size_t& i) { if (i + 1 < args.size()) { return args[++i]; } else { - std::cerr << "Error: Missing value for " << flag << " option.\n"; + std::println("Error: Missing value for {} option.", flag); return std::nullopt; } } @@ -48,11 +48,11 @@ int main(int argc, char** argv, char** envp) { if (arg == "--version" || arg == "-V") { constexpr bool ISTAGGEDRELEASE = std::string_view(HYPRLOCK_COMMIT) == HYPRLOCK_VERSION_COMMIT; + if (ISTAGGEDRELEASE) + std::println("Hyprlock version v{}", HYPRLOCK_VERSION); + else + std::println("Hyprlock version v{} (commit {})", HYPRLOCK_VERSION, HYPRLOCK_VERSION_COMMIT); - std::cout << "Hyprlock version v" << HYPRLOCK_VERSION; - if (!ISTAGGEDRELEASE) - std::cout << " (commit " << HYPRLOCK_COMMIT << ")"; - std::cout << std::endl; return 0; } @@ -84,7 +84,7 @@ int main(int argc, char** argv, char** envp) { noFadeIn = true; else { - std::cerr << "Unknown option: " << arg << "\n"; + std::println(stderr, "Unknown option: {}", arg); help(); return 1; }