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/config/ConfigManager.cpp | 118 +++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 61 deletions(-) (limited to 'src/config/ConfigManager.cpp') diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 94147f49..1af5fb15 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -90,7 +90,7 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** try { DATA->m_angle = std::stoi(std::string(var.substr(0, var.find("deg")))) * (PI / 180.0); // radians } catch (...) { - Debug::log(WARN, "Error parsing gradient {}", V); + Log::logger->log(Log::WARN, "Error parsing gradient {}", V); parseError = "Error parsing gradient " + V; } @@ -98,7 +98,7 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** } if (DATA->m_colors.size() >= 10) { - Debug::log(WARN, "Error parsing gradient {}: max colors is 10.", V); + Log::logger->log(Log::WARN, "Error parsing gradient {}: max colors is 10.", V); parseError = "Error parsing gradient " + V + ": max colors is 10."; break; } @@ -109,13 +109,13 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** throw std::runtime_error(std::format("failed to parse {} as a color", var)); DATA->m_colors.emplace_back(COL.value()); } catch (std::exception& e) { - Debug::log(WARN, "Error parsing gradient {}", V); + Log::logger->log(Log::WARN, "Error parsing gradient {}", V); parseError = "Error parsing gradient " + V + ": " + e.what(); } } if (DATA->m_colors.empty()) { - Debug::log(WARN, "Error parsing gradient {}", V); + Log::logger->log(Log::WARN, "Error parsing gradient {}", V); if (parseError.empty()) parseError = "Error parsing gradient " + V + ": No colors?"; @@ -880,18 +880,16 @@ CConfigManager::CConfigManager() { resetHLConfig(); if (CONFIG_OPTIONS.size() != m_configValueNumber - 1 /* autogenerated is special */) - Debug::log(LOG, "Warning: config descriptions have {} entries, but there are {} config values. This should fail tests!!", CONFIG_OPTIONS.size(), m_configValueNumber); + Log::logger->log(Log::DEBUG, "Warning: config descriptions have {} entries, but there are {} config values. This should fail tests!!", CONFIG_OPTIONS.size(), + m_configValueNumber); if (!g_pCompositor->m_onlyConfigVerification) { - Debug::log( - INFO, + Log::logger->log( + Log::DEBUG, "!!!!HEY YOU, YES YOU!!!!: further logs to stdout / logfile are disabled by default. BEFORE SENDING THIS LOG, ENABLE THEM. Use debug:disable_logs = false to do so: " "https://wiki.hypr.land/Configuring/Variables/#debug"); } - Debug::m_disableLogs = rc(m_config->getConfigValuePtr("debug:disable_logs")->getDataStaticPtr()); - Debug::m_disableTime = rc(m_config->getConfigValuePtr("debug:disable_time")->getDataStaticPtr()); - if (g_pEventLoopManager && ERR.has_value()) g_pEventLoopManager->doLater([ERR] { g_pHyprError->queueCreate(ERR.value(), CHyprColor{1.0, 0.1, 0.1, 1.0}); }); } @@ -923,14 +921,14 @@ std::optional CConfigManager::generateConfig(std::string configPath std::error_code ec; bool created = std::filesystem::create_directories(parentPath, ec); if (ec) { - Debug::log(ERR, "Couldn't create config home directory ({}): {}", ec.message(), parentPath); + Log::logger->log(Log::ERR, "Couldn't create config home directory ({}): {}", ec.message(), parentPath); return "Config could not be generated."; } if (created) - Debug::log(WARN, "Creating config home directory"); + Log::logger->log(Log::WARN, "Creating config home directory"); } - Debug::log(WARN, "No config file found; attempting to generate."); + Log::logger->log(Log::WARN, "No config file found; attempting to generate."); std::ofstream ofs; ofs.open(configPath, std::ios::trunc); if (!safeMode) { @@ -1002,7 +1000,7 @@ std::string CConfigManager::getConfigString() { std::ifstream configFile(path); configString += ("\n\nConfig File: " + path + ": "); if (!configFile.is_open()) { - Debug::log(LOG, "Config file not readable/found!"); + Log::logger->log(Log::DEBUG, "Config file not readable/found!"); configString += "Read Failed\n"; continue; } @@ -1129,7 +1127,7 @@ std::optional CConfigManager::resetHLConfig() { // paths m_configPaths.clear(); std::string mainConfigPath = getMainConfigPath(); - Debug::log(LOG, "Using config: {}", mainConfigPath); + Log::logger->log(Log::DEBUG, "Using config: {}", mainConfigPath); m_configPaths.emplace_back(mainConfigPath); const auto RET = verifyConfigExists(); @@ -1397,11 +1395,9 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) { g_pHyprRenderer->initiateManualCrash(); } - Debug::m_disableStdout = !std::any_cast(m_config->getConfigValue("debug:enable_stdout_logs")); - if (Debug::m_disableStdout && m_isFirstLaunch) - Debug::log(LOG, "Disabling stdout logs! Check the log for further logs."); - - Debug::m_coloredLogs = rc(m_config->getConfigValuePtr("debug:colored_stdout_logs")->getDataStaticPtr()); + auto disableStdout = !std::any_cast(m_config->getConfigValue("debug:enable_stdout_logs")); + if (disableStdout && m_isFirstLaunch) + Log::logger->log(Log::DEBUG, "Disabling stdout logs! Check the log for further logs."); for (auto const& m : g_pCompositor->m_monitors) { // mark blur dirty @@ -1435,7 +1431,7 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) { void CConfigManager::init() { g_pConfigWatcher->setOnChange([this](const CConfigWatcher::SConfigWatchEvent& e) { - Debug::log(LOG, "CConfigManager: file {} modified, reloading", e.file); + Log::logger->log(Log::DEBUG, "CConfigManager: file {} modified, reloading", e.file); reload(); }); @@ -1516,35 +1512,35 @@ SMonitorRule CConfigManager::getMonitorRuleFor(const PHLMONITOR PMONITOR) { if (!CONFIG) return rule; - Debug::log(LOG, "CConfigManager::getMonitorRuleFor: found a wlr_output_manager override for {}", PMONITOR->m_name); + Log::logger->log(Log::DEBUG, "CConfigManager::getMonitorRuleFor: found a wlr_output_manager override for {}", PMONITOR->m_name); - Debug::log(LOG, " > overriding enabled: {} -> {}", !rule.disabled, !CONFIG->enabled); + Log::logger->log(Log::DEBUG, " > overriding enabled: {} -> {}", !rule.disabled, !CONFIG->enabled); rule.disabled = !CONFIG->enabled; if ((CONFIG->committedProperties & OUTPUT_HEAD_COMMITTED_MODE) || (CONFIG->committedProperties & OUTPUT_HEAD_COMMITTED_CUSTOM_MODE)) { - Debug::log(LOG, " > overriding mode: {:.0f}x{:.0f}@{:.2f}Hz -> {:.0f}x{:.0f}@{:.2f}Hz", rule.resolution.x, rule.resolution.y, rule.refreshRate, CONFIG->resolution.x, - CONFIG->resolution.y, CONFIG->refresh / 1000.F); + Log::logger->log(Log::DEBUG, " > overriding mode: {:.0f}x{:.0f}@{:.2f}Hz -> {:.0f}x{:.0f}@{:.2f}Hz", rule.resolution.x, rule.resolution.y, rule.refreshRate, + CONFIG->resolution.x, CONFIG->resolution.y, CONFIG->refresh / 1000.F); rule.resolution = CONFIG->resolution; rule.refreshRate = CONFIG->refresh / 1000.F; } if (CONFIG->committedProperties & OUTPUT_HEAD_COMMITTED_POSITION) { - Debug::log(LOG, " > overriding offset: {:.0f}, {:.0f} -> {:.0f}, {:.0f}", rule.offset.x, rule.offset.y, CONFIG->position.x, CONFIG->position.y); + Log::logger->log(Log::DEBUG, " > overriding offset: {:.0f}, {:.0f} -> {:.0f}, {:.0f}", rule.offset.x, rule.offset.y, CONFIG->position.x, CONFIG->position.y); rule.offset = CONFIG->position; } if (CONFIG->committedProperties & OUTPUT_HEAD_COMMITTED_TRANSFORM) { - Debug::log(LOG, " > overriding transform: {} -> {}", sc(rule.transform), sc(CONFIG->transform)); + Log::logger->log(Log::DEBUG, " > overriding transform: {} -> {}", sc(rule.transform), sc(CONFIG->transform)); rule.transform = CONFIG->transform; } if (CONFIG->committedProperties & OUTPUT_HEAD_COMMITTED_SCALE) { - Debug::log(LOG, " > overriding scale: {} -> {}", sc(rule.scale), sc(CONFIG->scale)); + Log::logger->log(Log::DEBUG, " > overriding scale: {} -> {}", sc(rule.scale), sc(CONFIG->scale)); rule.scale = CONFIG->scale; } if (CONFIG->committedProperties & OUTPUT_HEAD_COMMITTED_ADAPTIVE_SYNC) { - Debug::log(LOG, " > overriding vrr: {} -> {}", rule.vrr.value_or(0), CONFIG->adaptiveSync); + Log::logger->log(Log::DEBUG, " > overriding vrr: {} -> {}", rule.vrr.value_or(0), CONFIG->adaptiveSync); rule.vrr = sc(CONFIG->adaptiveSync); } @@ -1557,7 +1553,7 @@ SMonitorRule CConfigManager::getMonitorRuleFor(const PHLMONITOR PMONITOR) { } } - Debug::log(WARN, "No rule found for {}, trying to use the first.", PMONITOR->m_name); + Log::logger->log(Log::WARN, "No rule found for {}, trying to use the first.", PMONITOR->m_name); for (auto const& r : m_monitorRules) { if (r.name.empty()) { @@ -1565,7 +1561,7 @@ SMonitorRule CConfigManager::getMonitorRuleFor(const PHLMONITOR PMONITOR) { } } - Debug::log(WARN, "No rules configured. Using the default hardcoded one."); + Log::logger->log(Log::WARN, "No rules configured. Using the default hardcoded one."); return applyWlrOutputConfig(SMonitorRule{.autoDir = eAutoDirs::DIR_AUTO_RIGHT, .name = "", @@ -1767,7 +1763,7 @@ void CConfigManager::ensureVRR(PHLMONITOR pMonitor) { m->m_output->state->setAdaptiveSync(false); if (!m->m_state.commit()) - Debug::log(ERR, "Couldn't commit output {} in ensureVRR -> false", m->m_output->name); + Log::logger->log(Log::ERR, "Couldn't commit output {} in ensureVRR -> false", m->m_output->name); } m->m_vrrActive = false; return; @@ -1777,12 +1773,12 @@ void CConfigManager::ensureVRR(PHLMONITOR pMonitor) { m->m_output->state->setAdaptiveSync(true); if (!m->m_state.test()) { - Debug::log(LOG, "Pending output {} does not accept VRR.", m->m_output->name); + Log::logger->log(Log::DEBUG, "Pending output {} does not accept VRR.", m->m_output->name); m->m_output->state->setAdaptiveSync(false); } if (!m->m_state.commit()) - Debug::log(ERR, "Couldn't commit output {} in ensureVRR -> true", m->m_output->name); + Log::logger->log(Log::ERR, "Couldn't commit output {} in ensureVRR -> true", m->m_output->name); } m->m_vrrActive = true; return; @@ -1809,7 +1805,7 @@ void CConfigManager::ensureVRR(PHLMONITOR pMonitor) { m->m_output->state->setAdaptiveSync(true); if (!m->m_state.test()) { - Debug::log(LOG, "Pending output {} does not accept VRR.", m->m_output->name); + Log::logger->log(Log::DEBUG, "Pending output {} does not accept VRR.", m->m_output->name); m->m_output->state->setAdaptiveSync(false); } } @@ -1981,7 +1977,7 @@ static bool parseModeLine(const std::string& modeline, drmModeModeInfo& mode) { return false; if (args.size() < 10) { - Debug::log(ERR, "modeline parse error: expected at least 9 arguments, got {}", args.size() - 1); + Log::logger->log(Log::ERR, "modeline parse error: expected at least 9 arguments, got {}", args.size() - 1); return false; } @@ -2000,7 +1996,7 @@ static bool parseModeLine(const std::string& modeline, drmModeModeInfo& mode) { mode.vtotal = std::stoi(args[argno++]); mode.vrefresh = mode.clock * 1000.0 * 1000.0 / mode.htotal / mode.vtotal; } catch (const std::exception& e) { - Debug::log(ERR, "modeline parse error: invalid numeric value: {}", e.what()); + Log::logger->log(Log::ERR, "modeline parse error: invalid numeric value: {}", e.what()); return false; } @@ -2023,7 +2019,7 @@ static bool parseModeLine(const std::string& modeline, drmModeModeInfo& mode) { if (it != flagsmap.end()) mode.flags |= it->second; else - Debug::log(ERR, "Invalid flag {} in modeline", key); + Log::logger->log(Log::ERR, "Invalid flag {} in modeline", key); } snprintf(mode.name, sizeof(mode.name), "%dx%d@%d", mode.hdisplay, mode.vdisplay, mode.vrefresh / 1000); @@ -2105,11 +2101,11 @@ bool CMonitorRuleParser::parsePosition(const std::string& value, bool isFirst) { else if (value == "auto-center-down") m_rule.autoDir = eAutoDirs::DIR_AUTO_CENTER_DOWN; else { - Debug::log(WARN, - "Invalid auto direction. Valid options are 'auto'," - "'auto-up', 'auto-down', 'auto-left', 'auto-right'," - "'auto-center-up', 'auto-center-down'," - "'auto-center-left', and 'auto-center-right'."); + Log::logger->log(Log::WARN, + "Invalid auto direction. Valid options are 'auto'," + "'auto-up', 'auto-down', 'auto-left', 'auto-right'," + "'auto-center-up', 'auto-center-down'," + "'auto-center-left', and 'auto-center-right'."); m_error += "invalid auto direction "; return false; } @@ -2160,7 +2156,7 @@ bool CMonitorRuleParser::parseTransform(const std::string& value) { const auto TSF = std::stoi(value); if (std::clamp(TSF, 0, 7) != TSF) { - Debug::log(ERR, "Invalid transform {} in monitor", TSF); + Log::logger->log(Log::ERR, "Invalid transform {} in monitor", TSF); m_error += "invalid transform "; return false; } @@ -2268,7 +2264,7 @@ std::optional CConfigManager::handleMonitor(const std::string& comm // fall } else { - Debug::log(ERR, "ConfigManager parseMonitor, curitem bogus???"); + Log::logger->log(Log::ERR, "ConfigManager parseMonitor, curitem bogus???"); return "parse error: curitem bogus"; } @@ -2319,7 +2315,7 @@ std::optional CConfigManager::handleMonitor(const std::string& comm m_workspaceRules.emplace_back(wsRule); argno++; } else { - Debug::log(ERR, "Config error: invalid monitor syntax at \"{}\"", ARGS[argno]); + Log::logger->log(Log::ERR, "Config error: invalid monitor syntax at \"{}\"", ARGS[argno]); return "invalid syntax at \"" + std::string(ARGS[argno]) + "\""; } @@ -2536,12 +2532,12 @@ std::optional CConfigManager::handleBind(const std::string& command const auto DISPATCHER = g_pKeybindManager->m_dispatchers.find(HANDLER); if (DISPATCHER == g_pKeybindManager->m_dispatchers.end()) { - Debug::log(ERR, "Invalid dispatcher: {}", HANDLER); + Log::logger->log(Log::ERR, "Invalid dispatcher: {}", HANDLER); return "Invalid dispatcher, requested \"" + HANDLER + "\" does not exist"; } if (MOD == 0 && !MODSTR.empty()) { - Debug::log(ERR, "Invalid mod: {}", MODSTR); + Log::logger->log(Log::ERR, "Invalid mod: {}", MODSTR); return "Invalid mod, requested mod \"" + MODSTR + "\" is not a valid mod."; } @@ -2549,7 +2545,7 @@ std::optional CConfigManager::handleBind(const std::string& command SParsedKey parsedKey = parseKey(KEY); if (parsedKey.catchAll && m_currentSubmap.name.empty()) { - Debug::log(ERR, "Catchall not allowed outside of submap!"); + Log::logger->log(Log::ERR, "Catchall not allowed outside of submap!"); return "Invalid catchall, catchall keybinds are only allowed in submaps."; } @@ -2599,7 +2595,7 @@ std::optional CConfigManager::handleWorkspaceRules(const std::strin // auto wsIdent = removeBeginEndSpacesTabs(value.substr(FIRST_DELIM + 1, (WORKSPACE_DELIM - FIRST_DELIM - 1))); // id = getWorkspaceIDFromString(wsIdent, name); // if (id == WORKSPACE_INVALID) { - // Debug::log(ERR, "Invalid workspace identifier found: {}", wsIdent); + // Log::logger->log(Log::ERR, "Invalid workspace identifier found: {}", wsIdent); // return "Invalid workspace identifier found: " + wsIdent; // } // wsRule.monitor = first_ident; @@ -2665,7 +2661,7 @@ std::optional CConfigManager::handleWorkspaceRules(const std::strin std::string opt = rule.substr(delim + 10); if (!opt.contains(":")) { // invalid - Debug::log(ERR, "Invalid workspace rule found: {}", rule); + Log::logger->log(Log::ERR, "Invalid workspace rule found: {}", rule); return "Invalid workspace rule found: " + rule; } @@ -2709,7 +2705,7 @@ std::optional CConfigManager::handleSubmap(const std::string&, cons std::optional CConfigManager::handleSource(const std::string& command, const std::string& rawpath) { if (rawpath.length() < 2) { - Debug::log(ERR, "source= path garbage"); + Log::logger->log(Log::ERR, "source= path garbage"); return "source= path " + rawpath + " bogus!"; } @@ -2723,7 +2719,7 @@ std::optional CConfigManager::handleSource(const std::string& comma if (auto r = glob(absolutePath(rawpath, m_configCurrentPath).c_str(), GLOB_TILDE, nullptr, glob_buf.get()); r != 0) { std::string err = std::format("source= globbing error: {}", r == GLOB_NOMATCH ? "found no match" : GLOB_ABORTED ? "read error" : "out of memory"); - Debug::log(ERR, "{}", err); + Log::logger->log(Log::ERR, "{}", err); return err; } @@ -2736,7 +2732,7 @@ std::optional CConfigManager::handleSource(const std::string& comma auto file_status = std::filesystem::status(value, ec); if (ec) { - Debug::log(ERR, "source= file from glob result is inaccessible ({}): {}", ec.message(), value); + Log::logger->log(Log::ERR, "source= file from glob result is inaccessible ({}): {}", ec.message(), value); return "source= file " + value + " is inaccessible!"; } @@ -2749,10 +2745,10 @@ std::optional CConfigManager::handleSource(const std::string& comma if (THISRESULT.error && errorsFromParsing.empty()) errorsFromParsing += THISRESULT.getError(); } else if (std::filesystem::is_directory(file_status)) { - Debug::log(WARN, "source= skipping directory {}", value); + Log::logger->log(Log::WARN, "source= skipping directory {}", value); continue; } else { - Debug::log(WARN, "source= skipping non-regular-file {}", value); + Log::logger->log(Log::WARN, "source= skipping non-regular-file {}", value); continue; } } @@ -3007,7 +3003,7 @@ std::string SConfigOptionDescription::jsonify() const { [this](auto&& val) { const auto PTR = g_pConfigManager->m_config->getConfigValuePtr(value.c_str()); if (!PTR) { - Debug::log(ERR, "invalid SConfigOptionDescription: no config option {} exists", value); + Log::logger->log(Log::ERR, "invalid SConfigOptionDescription: no config option {} exists", value); return std::string{""}; } const char* const EXPLICIT = PTR->m_bSetByUser ? "true" : "false"; @@ -3084,7 +3080,7 @@ std::string SConfigOptionDescription::jsonify() const { val.gradient, currentValue, EXPLICIT); } - } catch (std::bad_any_cast& e) { Debug::log(ERR, "Bad any_cast on value {} in descriptions", value); } + } catch (std::bad_any_cast& e) { Log::logger->log(Log::ERR, "Bad any_cast on value {} in descriptions", value); } return std::string{""}; }, data); @@ -3109,7 +3105,7 @@ void CConfigManager::ensurePersistentWorkspacesPresent() { } void CConfigManager::storeFloatingSize(PHLWINDOW window, const Vector2D& size) { - Debug::log(LOG, "storing floating size {}x{} for window {}::{}", size.x, size.y, window->m_initialClass, window->m_initialTitle); + Log::logger->log(Log::DEBUG, "storing floating size {}x{} for window {}::{}", size.x, size.y, window->m_initialClass, window->m_initialTitle); // true -> use m_initialClass and m_initialTitle SFloatCache id{window, true}; m_mStoredFloatingSizes[id] = size; @@ -3120,9 +3116,9 @@ std::optional CConfigManager::getStoredFloatingSize(PHLWINDOW window) // and m_class and m_title are just "initial" ones. // false -> use m_class and m_title SFloatCache id{window, false}; - Debug::log(LOG, "Hash for window {}::{} = {}", window->m_class, window->m_title, id.hash); + Log::logger->log(Log::DEBUG, "Hash for window {}::{} = {}", window->m_class, window->m_title, id.hash); if (m_mStoredFloatingSizes.contains(id)) { - Debug::log(LOG, "got stored size {}x{} for window {}::{}", m_mStoredFloatingSizes[id].x, m_mStoredFloatingSizes[id].y, window->m_class, window->m_title); + Log::logger->log(Log::DEBUG, "got stored size {}x{} for window {}::{}", m_mStoredFloatingSizes[id].x, m_mStoredFloatingSizes[id].y, window->m_class, window->m_title); return m_mStoredFloatingSizes[id]; } return std::nullopt; -- cgit v1.2.3