mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 20:45:59 +01:00
log: Add some colors to stdout log 🔴🟡🟢🔵🟣 (#5778)
* add colored log * add config option * make it dynamic
This commit is contained in:
parent
33e0bb1478
commit
a783cd8f40
3 changed files with 32 additions and 9 deletions
|
@ -377,6 +377,7 @@ CConfigManager::CConfigManager() {
|
||||||
m_pConfig->addConfigValue("debug:error_limit", Hyprlang::INT{5});
|
m_pConfig->addConfigValue("debug:error_limit", Hyprlang::INT{5});
|
||||||
m_pConfig->addConfigValue("debug:watchdog_timeout", Hyprlang::INT{5});
|
m_pConfig->addConfigValue("debug:watchdog_timeout", Hyprlang::INT{5});
|
||||||
m_pConfig->addConfigValue("debug:disable_scale_checks", Hyprlang::INT{0});
|
m_pConfig->addConfigValue("debug:disable_scale_checks", Hyprlang::INT{0});
|
||||||
|
m_pConfig->addConfigValue("debug:colored_stdout_logs", Hyprlang::INT{1});
|
||||||
|
|
||||||
m_pConfig->addConfigValue("decoration:rounding", Hyprlang::INT{0});
|
m_pConfig->addConfigValue("decoration:rounding", Hyprlang::INT{0});
|
||||||
m_pConfig->addConfigValue("decoration:blur:enabled", Hyprlang::INT{1});
|
m_pConfig->addConfigValue("decoration:blur:enabled", Hyprlang::INT{1});
|
||||||
|
@ -592,7 +593,7 @@ CConfigManager::CConfigManager() {
|
||||||
setDefaultAnimationVars();
|
setDefaultAnimationVars();
|
||||||
resetHLConfig();
|
resetHLConfig();
|
||||||
|
|
||||||
Debug::log(LOG,
|
Debug::log(INFO,
|
||||||
"!!!!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: "
|
"!!!!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.hyprland.org/Configuring/Variables/#debug");
|
"https://wiki.hyprland.org/Configuring/Variables/#debug");
|
||||||
|
|
||||||
|
@ -818,6 +819,8 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) {
|
||||||
if (Debug::disableStdout && isFirstLaunch)
|
if (Debug::disableStdout && isFirstLaunch)
|
||||||
Debug::log(LOG, "Disabling stdout logs! Check the log for further logs.");
|
Debug::log(LOG, "Disabling stdout logs! Check the log for further logs.");
|
||||||
|
|
||||||
|
Debug::coloredLogs = reinterpret_cast<int64_t* const*>(m_pConfig->getConfigValuePtr("debug:colored_stdout_logs")->getDataStaticPtr());
|
||||||
|
|
||||||
for (auto& m : g_pCompositor->m_vMonitors) {
|
for (auto& m : g_pCompositor->m_vMonitors) {
|
||||||
// mark blur dirty
|
// mark blur dirty
|
||||||
g_pHyprOpenGL->markBlurDirtyForMonitor(m.get());
|
g_pHyprOpenGL->markBlurDirtyForMonitor(m.get());
|
||||||
|
|
|
@ -40,13 +40,32 @@ void Debug::log(LogLevel level, std::string str) {
|
||||||
if (shuttingDown)
|
if (shuttingDown)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
std::string coloredStr = str;
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case LOG: str = "[LOG] " + str; break;
|
case LOG:
|
||||||
case WARN: str = "[WARN] " + str; break;
|
str = "[LOG] " + str;
|
||||||
case ERR: str = "[ERR] " + str; break;
|
coloredStr = str;
|
||||||
case CRIT: str = "[CRITICAL] " + str; break;
|
break;
|
||||||
case INFO: str = "[INFO] " + str; break;
|
case WARN:
|
||||||
case TRACE: str = "[TRACE] " + str; break;
|
str = "[WARN] " + str;
|
||||||
|
coloredStr = "\033[1;33m" + str + "\033[0m"; // yellow
|
||||||
|
break;
|
||||||
|
case ERR:
|
||||||
|
str = "[ERR] " + str;
|
||||||
|
coloredStr = "\033[1;31m" + str + "\033[0m"; // red
|
||||||
|
break;
|
||||||
|
case CRIT:
|
||||||
|
str = "[CRITICAL] " + str;
|
||||||
|
coloredStr = "\033[1;35m" + str + "\033[0m"; // magenta
|
||||||
|
break;
|
||||||
|
case INFO:
|
||||||
|
str = "[INFO] " + str;
|
||||||
|
coloredStr = "\033[1;32m" + str + "\033[0m"; // green
|
||||||
|
break;
|
||||||
|
case TRACE:
|
||||||
|
str = "[TRACE] " + str;
|
||||||
|
coloredStr = "\033[1;34m" + str + "\033[0m"; // blue
|
||||||
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,5 +84,5 @@ void Debug::log(LogLevel level, std::string str) {
|
||||||
|
|
||||||
// log it to the stdout too.
|
// log it to the stdout too.
|
||||||
if (!disableStdout)
|
if (!disableStdout)
|
||||||
std::cout << str << "\n";
|
std::cout << ((coloredLogs && !**coloredLogs) ? str : coloredStr) << "\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace Debug {
|
||||||
inline bool disableStdout = false;
|
inline bool disableStdout = false;
|
||||||
inline bool trace = false;
|
inline bool trace = false;
|
||||||
inline bool shuttingDown = false;
|
inline bool shuttingDown = false;
|
||||||
|
inline int64_t* const* coloredLogs = nullptr;
|
||||||
|
|
||||||
inline std::string rollingLog = ""; // rolling log contains the ROLLING_LOG_SIZE tail of the log
|
inline std::string rollingLog = ""; // rolling log contains the ROLLING_LOG_SIZE tail of the log
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue