From 673929f16920c277246a75409526143cebe1bc39 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 12 Mar 2022 14:57:37 +0200 Subject: [PATCH] logger: with MU_LOG_STDOUTERR, write logs to console For debugging --- lib/utils/mu-logger.cc | 11 +++++++---- lib/utils/mu-logger.hh | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/utils/mu-logger.cc b/lib/utils/mu-logger.cc index b1f3a054..40ac4e02 100644 --- a/lib/utils/mu-logger.cc +++ b/lib/utils/mu-logger.cc @@ -122,6 +122,9 @@ Mu::log_init(const std::string& path, Mu::LogOptions opts) return; } + if (g_getenv("MU_LOG_STDOUTERR")) + opts |= LogOptions::StdOutErr; + MuLogOptions = opts; 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) { // filter out debug-level messages? if (level == G_LOG_LEVEL_DEBUG && - (none_of(MuLogOptions & Mu::LogOptions::Debug))) + (none_of(MuLogOptions & Mu::LogOptions::Debug))) return G_LOG_WRITER_HANDLED; // log criticals to stdout / err or if asked 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); } @@ -148,8 +151,8 @@ Mu::log_init(const std::string& path, Mu::LogOptions opts) NULL); g_message("logging initialized; debug: %s, stdout/stderr: %s", - any_of(log_get_options() & LogOptions::Debug) ? "yes" : "no", - any_of(log_get_options() & LogOptions::StdOutErr) ? "yes" : "no"); + any_of(log_get_options() & LogOptions::Debug) ? "yes" : "no", + any_of(log_get_options() & LogOptions::StdOutErr) ? "yes" : "no"); MuLogInitialized = true; } diff --git a/lib/utils/mu-logger.hh b/lib/utils/mu-logger.hh index 15e983f2..61b187be 100644 --- a/lib/utils/mu-logger.hh +++ b/lib/utils/mu-logger.hh @@ -40,6 +40,9 @@ enum struct LogOptions { * logging fails -- practically, it goes to the file if there's * systemd/journald. * + * if the environment variable MU_LOG_STDOUTERR is set, LogOptions::StdoutErr is + * implied. + * * @param path path to the log file * @param opts logging options */