Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some colors to stdout log 馃敶馃煛馃煝馃數馃煟 #5778

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ CConfigManager::CConfigManager() {
m_pConfig->addConfigValue("debug:error_limit", 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:colored_stdout_logs", Hyprlang::INT{1});

m_pConfig->addConfigValue("decoration:rounding", Hyprlang::INT{0});
m_pConfig->addConfigValue("decoration:blur:enabled", Hyprlang::INT{1});
Expand Down Expand Up @@ -592,7 +593,7 @@ CConfigManager::CConfigManager() {
setDefaultAnimationVars();
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: "
"https://wiki.hyprland.org/Configuring/Variables/#debug");

Expand Down Expand Up @@ -818,6 +819,8 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) {
if (Debug::disableStdout && isFirstLaunch)
Debug::log(LOG, "Disabling stdout logs! Check the log for further logs.");

Debug::coloredLogs = std::any_cast<Hyprlang::INT>(m_pConfig->getConfigValue("debug:colored_stdout_logs"));
vaxerski marked this conversation as resolved.
Show resolved Hide resolved

for (auto& m : g_pCompositor->m_vMonitors) {
// mark blur dirty
g_pHyprOpenGL->markBlurDirtyForMonitor(m.get());
Expand Down
35 changes: 27 additions & 8 deletions src/debug/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,32 @@ void Debug::log(LogLevel level, std::string str) {
if (shuttingDown)
return;

std::string coloredStr = str;
switch (level) {
case LOG: str = "[LOG] " + str; break;
case WARN: str = "[WARN] " + str; break;
case ERR: str = "[ERR] " + str; break;
case CRIT: str = "[CRITICAL] " + str; break;
case INFO: str = "[INFO] " + str; break;
case TRACE: str = "[TRACE] " + str; break;
case LOG:
str = "[LOG] " + str;
coloredStr = str;
break;
case WARN:
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;
}

Expand All @@ -65,5 +84,5 @@ void Debug::log(LogLevel level, std::string str) {

// log it to the stdout too.
if (!disableStdout)
std::cout << str << "\n";
}
std::cout << (coloredLogs ? coloredStr : str) << "\n";
}
1 change: 1 addition & 0 deletions src/debug/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Debug {
inline bool disableStdout = false;
inline bool trace = false;
inline bool shuttingDown = false;
inline bool coloredLogs = true;

inline std::string rollingLog = ""; // rolling log contains the ROLLING_LOG_SIZE tail of the log

Expand Down