From 6175ecd4c4ba817c4620f66a75e1e11da7c7a8ca Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Thu, 18 Dec 2025 17:23:24 +0000 Subject: debug: move to hyprutils' logger (#12673) --- src/plugins/HookSystem.cpp | 28 ++++++++++++++-------------- src/plugins/PluginAPI.cpp | 6 +++--- src/plugins/PluginSystem.cpp | 34 +++++++++++++++++----------------- 3 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/HookSystem.cpp b/src/plugins/HookSystem.cpp index 031b1def..f17a4556 100644 --- a/src/plugins/HookSystem.cpp +++ b/src/plugins/HookSystem.cpp @@ -1,5 +1,5 @@ #include "HookSystem.hpp" -#include "../debug/Log.hpp" +#include "../debug/log/Logger.hpp" #include "../helpers/varlist/VarList.hpp" #include "../managers/TokenManager.hpp" #include "../helpers/MiscFunctions.hpp" @@ -146,7 +146,7 @@ bool CFunctionHook::hook() { if (g_pFunctionHookSystem->m_activeHooks.contains(rc(m_source))) { // TODO: return actual error codes... - Debug::log(ERR, "[functionhook] failed, function is already hooked"); + Log::logger->log(Log::ERR, "[functionhook] failed, function is already hooked"); return false; } @@ -174,12 +174,12 @@ bool CFunctionHook::hook() { const auto PROBEFIXEDASM = fixInstructionProbeRIPCalls(probe); if (PROBEFIXEDASM.bytes.empty()) { - Debug::log(ERR, "[functionhook] failed, unsupported asm / failed assembling:\n{}", probe.assembly); + Log::logger->log(Log::ERR, "[functionhook] failed, unsupported asm / failed assembling:\n{}", probe.assembly); return false; } if (std::abs(rc(m_source) - rc(m_landTrampolineAddr)) > 2000000000 /* 2 GB */) { - Debug::log(ERR, "[functionhook] failed, source and trampo are over 2GB apart"); + Log::logger->log(Log::ERR, "[functionhook] failed, source and trampo are over 2GB apart"); return false; } @@ -189,7 +189,7 @@ bool CFunctionHook::hook() { const auto TRAMPOLINE_SIZE = sizeof(RELATIVE_JMP_ADDRESS) + HOOKSIZE; if (TRAMPOLINE_SIZE > MAX_TRAMPOLINE_SIZE) { - Debug::log(ERR, "[functionhook] failed, not enough space in trampo to alloc:\n{}", probe.assembly); + Log::logger->log(Log::ERR, "[functionhook] failed, not enough space in trampo to alloc:\n{}", probe.assembly); return false; } @@ -300,7 +300,7 @@ static uintptr_t seekNewPageAddr() { uint64_t start = 0, end = 0; if (props[0].empty()) { - Debug::log(WARN, "seekNewPageAddr: unexpected line in self maps"); + Log::logger->log(Log::WARN, "seekNewPageAddr: unexpected line in self maps"); continue; } @@ -310,11 +310,11 @@ static uintptr_t seekNewPageAddr() { start = std::stoull(startEnd[0], nullptr, 16); end = std::stoull(startEnd[1], nullptr, 16); } catch (std::exception& e) { - Debug::log(WARN, "seekNewPageAddr: unexpected line in self maps: {}", line); + Log::logger->log(Log::WARN, "seekNewPageAddr: unexpected line in self maps: {}", line); continue; } - Debug::log(LOG, "seekNewPageAddr: page 0x{:x} - 0x{:x}", start, end); + Log::logger->log(Log::DEBUG, "seekNewPageAddr: page 0x{:x} - 0x{:x}", start, end); if (lastStart == 0) { lastStart = start; @@ -323,17 +323,17 @@ static uintptr_t seekNewPageAddr() { } if (!anchoredToHyprland && line.contains("Hyprland")) { - Debug::log(LOG, "seekNewPageAddr: Anchored to hyprland at 0x{:x}", start); + Log::logger->log(Log::DEBUG, "seekNewPageAddr: Anchored to hyprland at 0x{:x}", start); anchoredToHyprland = true; } else if (start - lastEnd > PAGESIZE_VAR * 2) { if (!anchoredToHyprland) { - Debug::log(LOG, "seekNewPageAddr: skipping gap 0x{:x}-0x{:x}, not anchored to Hyprland code pages yet.", lastEnd, start); + Log::logger->log(Log::DEBUG, "seekNewPageAddr: skipping gap 0x{:x}-0x{:x}, not anchored to Hyprland code pages yet.", lastEnd, start); lastStart = start; lastEnd = end; continue; } - Debug::log(LOG, "seekNewPageAddr: found gap: 0x{:x}-0x{:x} ({} bytes)", lastEnd, start, start - lastEnd); + Log::logger->log(Log::DEBUG, "seekNewPageAddr: found gap: 0x{:x}-0x{:x} ({} bytes)", lastEnd, start, start - lastEnd); MAPS.close(); return lastEnd; } @@ -365,7 +365,7 @@ uint64_t CHookSystem::getAddressForTrampo() { if (!page->addr) { // allocate it - Debug::log(LOG, "getAddressForTrampo: Allocating new page for hooks"); + Log::logger->log(Log::DEBUG, "getAddressForTrampo: Allocating new page for hooks"); const uint64_t PAGESIZE_VAR = sysconf(_SC_PAGE_SIZE); const auto BASEPAGEADDR = seekNewPageAddr(); for (int attempt = 0; attempt < 2; ++attempt) { @@ -376,7 +376,7 @@ uint64_t CHookSystem::getAddressForTrampo() { page->len = PAGESIZE_VAR; page->used = 0; - Debug::log(LOG, "Attempted to allocate 0x{:x}, got 0x{:x}", PAGEADDR, page->addr); + Log::logger->log(Log::DEBUG, "Attempted to allocate 0x{:x}, got 0x{:x}", PAGEADDR, page->addr); if (page->addr == rc(MAP_FAILED)) continue; @@ -398,7 +398,7 @@ uint64_t CHookSystem::getAddressForTrampo() { page->used += HOOK_TRAMPOLINE_MAX_SIZE; - Debug::log(LOG, "getAddressForTrampo: Returning addr 0x{:x} for page at 0x{:x}", ADDRFORCONSUMER, page->addr); + Log::logger->log(Log::DEBUG, "getAddressForTrampo: Returning addr 0x{:x} for page at 0x{:x}", ADDRFORCONSUMER, page->addr); return ADDRFORCONSUMER; } diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index 66b0c74e..1d6586aa 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -350,11 +350,11 @@ APICALL std::vector HyprlandAPI::findFunctionsByName(HANDLE hand }; if (SYMBOLS.empty()) { - Debug::log(ERR, R"(Unable to search for function "{}": no symbols found in binary (is "{}" in path?))", name, + Log::logger->log(Log::ERR, R"(Unable to search for function "{}": no symbols found in binary (is "{}" in path?))", name, #ifdef __clang__ - "llvm-nm" + "llvm-nm" #else - "nm" + "nm" #endif ); return {}; diff --git a/src/plugins/PluginSystem.cpp b/src/plugins/PluginSystem.cpp index 27e8232e..53b05bc8 100644 --- a/src/plugins/PluginSystem.cpp +++ b/src/plugins/PluginSystem.cpp @@ -25,7 +25,7 @@ SP> CPluginSystem::loadPlugin(const std::string& path, eSpeci return CPromise::make([path, pid, pidType, this](SP> resolver) { const auto PERM = g_pDynamicPermissionManager->clientPermissionModeWithString(pidType != SPECIAL_PID_TYPE_NONE ? pidType : pid, path, PERMISSION_TYPE_PLUGIN); if (PERM == PERMISSION_RULE_ALLOW_MODE_PENDING) { - Debug::log(LOG, "CPluginSystem: Waiting for user confirmation to load {}", path); + Log::logger->log(Log::DEBUG, "CPluginSystem: Waiting for user confirmation to load {}", path); auto promise = g_pDynamicPermissionManager->promiseFor(pid, path, PERMISSION_TYPE_PLUGIN); if (!promise) { // already awaiting or something? @@ -35,18 +35,18 @@ SP> CPluginSystem::loadPlugin(const std::string& path, eSpeci promise->then([this, path, resolver](SP> result) { if (result->hasError()) { - Debug::log(ERR, "CPluginSystem: Error spawning permission prompt"); + Log::logger->log(Log::ERR, "CPluginSystem: Error spawning permission prompt"); resolver->reject("Error spawning permission prompt"); return; } if (result->result() != PERMISSION_RULE_ALLOW_MODE_ALLOW) { - Debug::log(ERR, "CPluginSystem: Rejecting plugin load of {}, user denied", path); + Log::logger->log(Log::ERR, "CPluginSystem: Rejecting plugin load of {}, user denied", path); resolver->reject("user denied"); return; } - Debug::log(LOG, "CPluginSystem: Loading {}, user allowed", path); + Log::logger->log(Log::DEBUG, "CPluginSystem: Loading {}, user allowed", path); const auto RESULT = loadPluginInternal(path); if (RESULT.has_value()) @@ -56,7 +56,7 @@ SP> CPluginSystem::loadPlugin(const std::string& path, eSpeci }); return; } else if (PERM == PERMISSION_RULE_ALLOW_MODE_DENY) { - Debug::log(LOG, "CPluginSystem: Rejecting plugin load, permission is disabled"); + Log::logger->log(Log::DEBUG, "CPluginSystem: Rejecting plugin load, permission is disabled"); resolver->reject("permission is disabled"); return; } @@ -71,7 +71,7 @@ SP> CPluginSystem::loadPlugin(const std::string& path, eSpeci std::expected CPluginSystem::loadPluginInternal(const std::string& path) { if (getPluginByPath(path)) { - Debug::log(ERR, " [PluginSystem] Cannot load a plugin twice!"); + Log::logger->log(Log::ERR, " [PluginSystem] Cannot load a plugin twice!"); return std::unexpected("Cannot load a plugin twice!"); } @@ -83,7 +83,7 @@ std::expected CPluginSystem::loadPluginInternal(const std if (!MODULE) { std::string strerr = dlerror(); - Debug::log(ERR, " [PluginSystem] Plugin {} could not be loaded: {}", path, strerr); + Log::logger->log(Log::ERR, " [PluginSystem] Plugin {} could not be loaded: {}", path, strerr); m_loadedPlugins.pop_back(); return std::unexpected(std::format("Plugin {} could not be loaded: {}", path, strerr)); } @@ -94,7 +94,7 @@ std::expected CPluginSystem::loadPluginInternal(const std PPLUGIN_INIT_FUNC initFunc = rc(dlsym(MODULE, PLUGIN_INIT_FUNC_STR)); if (!apiVerFunc || !initFunc) { - Debug::log(ERR, " [PluginSystem] Plugin {} could not be loaded. (No apiver/init func)", path); + Log::logger->log(Log::ERR, " [PluginSystem] Plugin {} could not be loaded. (No apiver/init func)", path); dlclose(MODULE); m_loadedPlugins.pop_back(); return std::unexpected(std::format("Plugin {} could not be loaded: {}", path, "missing apiver/init func")); @@ -103,7 +103,7 @@ std::expected CPluginSystem::loadPluginInternal(const std const std::string PLUGINAPIVER = apiVerFunc(); if (PLUGINAPIVER != HYPRLAND_API_VERSION) { - Debug::log(ERR, " [PluginSystem] Plugin {} could not be loaded. (API version mismatch)", path); + Log::logger->log(Log::ERR, " [PluginSystem] Plugin {} could not be loaded. (API version mismatch)", path); dlclose(MODULE); m_loadedPlugins.pop_back(); return std::unexpected(std::format("Plugin {} could not be loaded: {}", path, "API version mismatch")); @@ -121,7 +121,7 @@ std::expected CPluginSystem::loadPluginInternal(const std } } catch (std::exception& e) { m_allowConfigVars = false; - Debug::log(ERR, " [PluginSystem] Plugin {} (Handle {:x}) crashed in init. Unloading.", path, rc(MODULE)); + Log::logger->log(Log::ERR, " [PluginSystem] Plugin {} (Handle {:x}) crashed in init. Unloading.", path, rc(MODULE)); unloadPlugin(PLUGIN, true); // Plugin could've already hooked/done something return std::unexpected(std::format("Plugin {} could not be loaded: plugin crashed/threw in main: {}", path, e.what())); } @@ -135,8 +135,8 @@ std::expected CPluginSystem::loadPluginInternal(const std g_pEventLoopManager->doLater([] { g_pConfigManager->reload(); }); - Debug::log(LOG, R"( [PluginSystem] Plugin {} loaded. Handle: {:x}, path: "{}", author: "{}", description: "{}", version: "{}")", PLUGINDATA.name, rc(MODULE), path, - PLUGINDATA.author, PLUGINDATA.description, PLUGINDATA.version); + Log::logger->log(Log::DEBUG, R"( [PluginSystem] Plugin {} loaded. Handle: {:x}, path: "{}", author: "{}", description: "{}", version: "{}")", PLUGINDATA.name, + rc(MODULE), path, PLUGINDATA.author, PLUGINDATA.description, PLUGINDATA.version); return PLUGIN; } @@ -185,7 +185,7 @@ void CPluginSystem::unloadPlugin(const CPlugin* plugin, bool eject) { dlclose(PLHANDLE); - Debug::log(LOG, " [PluginSystem] Plugin {} unloaded.", PLNAME); + Log::logger->log(Log::DEBUG, " [PluginSystem] Plugin {} unloaded.", PLNAME); // reload config to fix some stuf like e.g. unloadedPluginVars g_pEventLoopManager->doLater([] { g_pConfigManager->reload(); }); @@ -207,7 +207,7 @@ void CPluginSystem::updateConfigPlugins(const std::vector& plugins, if (!p->m_loadedWithConfig || std::ranges::find(plugins, p->m_path) != plugins.end()) continue; - Debug::log(LOG, "Unloading plugin {} which is no longer present in config", p->m_path); + Log::logger->log(Log::DEBUG, "Unloading plugin {} which is no longer present in config", p->m_path); unloadPlugin(p.get(), false); changed = true; } @@ -217,14 +217,14 @@ void CPluginSystem::updateConfigPlugins(const std::vector& plugins, if (std::ranges::find_if(m_loadedPlugins, [&](const auto& other) { return other->m_path == path; }) != m_loadedPlugins.end()) continue; - Debug::log(LOG, "Loading plugin {} which is now present in config", path); + Log::logger->log(Log::DEBUG, "Loading plugin {} which is now present in config", path); changed = true; loadPlugin(path, SPECIAL_PID_TYPE_CONFIG)->then([path](SP> result) { if (result->hasError()) { const auto NAME = path.contains('/') ? path.substr(path.find_last_of('/') + 1) : path; - Debug::log(ERR, "CPluginSystem::updateConfigPlugins: failed to load plugin {}: {}", NAME, result->error()); + Log::logger->log(Log::ERR, "CPluginSystem::updateConfigPlugins: failed to load plugin {}: {}", NAME, result->error()); g_pHyprNotificationOverlay->addNotification(I18n::i18nEngine()->localize(I18n::TXT_KEY_NOTIF_FAILED_TO_LOAD_PLUGIN, {{"name", NAME}, {"error", result->error()}}), CHyprColor{0, 0, 0, 0}, 5000, ICON_ERROR); return; @@ -232,7 +232,7 @@ void CPluginSystem::updateConfigPlugins(const std::vector& plugins, result->result()->m_loadedWithConfig = true; - Debug::log(LOG, "CPluginSystem::updateConfigPlugins: loaded {}", path); + Log::logger->log(Log::DEBUG, "CPluginSystem::updateConfigPlugins: loaded {}", path); }); } } -- cgit v1.2.3