logger: with MU_LOG_STDOUTERR, write logs to console

For debugging
This commit is contained in:
Dirk-Jan C. Binnema
2022-03-12 14:57:37 +02:00
parent 5b121352c2
commit 673929f169
2 changed files with 10 additions and 4 deletions

View File

@ -122,6 +122,9 @@ Mu::log_init(const std::string& path, Mu::LogOptions opts)
return; return;
} }
if (g_getenv("MU_LOG_STDOUTERR"))
opts |= LogOptions::StdOutErr;
MuLogOptions = opts; MuLogOptions = opts;
MuLogPath = path; MuLogPath = path;
@ -129,12 +132,12 @@ Mu::log_init(const std::string& path, Mu::LogOptions opts)
[](GLogLevelFlags level, const GLogField* fields, gsize n_fields, gpointer user_data) { [](GLogLevelFlags level, const GLogField* fields, gsize n_fields, gpointer user_data) {
// filter out debug-level messages? // filter out debug-level messages?
if (level == G_LOG_LEVEL_DEBUG && if (level == G_LOG_LEVEL_DEBUG &&
(none_of(MuLogOptions & Mu::LogOptions::Debug))) (none_of(MuLogOptions & Mu::LogOptions::Debug)))
return G_LOG_WRITER_HANDLED; return G_LOG_WRITER_HANDLED;
// log criticals to stdout / err or if asked // log criticals to stdout / err or if asked
if (level == G_LOG_LEVEL_CRITICAL || if (level == G_LOG_LEVEL_CRITICAL ||
any_of(MuLogOptions & Mu::LogOptions::StdOutErr)) { any_of(MuLogOptions & Mu::LogOptions::StdOutErr)) {
log_stdouterr(level, fields, n_fields, user_data); log_stdouterr(level, fields, n_fields, user_data);
} }
@ -148,8 +151,8 @@ Mu::log_init(const std::string& path, Mu::LogOptions opts)
NULL); NULL);
g_message("logging initialized; debug: %s, stdout/stderr: %s", g_message("logging initialized; debug: %s, stdout/stderr: %s",
any_of(log_get_options() & LogOptions::Debug) ? "yes" : "no", any_of(log_get_options() & LogOptions::Debug) ? "yes" : "no",
any_of(log_get_options() & LogOptions::StdOutErr) ? "yes" : "no"); any_of(log_get_options() & LogOptions::StdOutErr) ? "yes" : "no");
MuLogInitialized = true; MuLogInitialized = true;
} }

View File

@ -40,6 +40,9 @@ enum struct LogOptions {
* logging fails -- practically, it goes to the file if there's * logging fails -- practically, it goes to the file if there's
* systemd/journald. * systemd/journald.
* *
* if the environment variable MU_LOG_STDOUTERR is set, LogOptions::StdoutErr is
* implied.
*
* @param path path to the log file * @param path path to the log file
* @param opts logging options * @param opts logging options
*/ */