[gnome-software] debug: Print debug and info messages to stdout, and warnings and higher to stderr
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] debug: Print debug and info messages to stdout, and warnings and higher to stderr
- Date: Fri, 8 Dec 2017 15:29:52 +0000 (UTC)
commit b22747cf3f3b3c480f3fb46af6ceeab05f8d640d
Author: Kalev Lember <klember redhat com>
Date: Fri Dec 8 16:18:53 2017 +0100
debug: Print debug and info messages to stdout, and warnings and higher to stderr
This makes it possible to do 'gnome-software --verbose >/dev/null' to
keep warnings/criticals on terminal and discard debug.
lib/gs-debug.c | 42 +++++++++++++++++++++++-------------------
1 files changed, 23 insertions(+), 19 deletions(-)
---
diff --git a/lib/gs-debug.c b/lib/gs-debug.c
index a683026..825424b 100644
--- a/lib/gs-debug.c
+++ b/lib/gs-debug.c
@@ -31,7 +31,6 @@ struct _GsDebug
GObject parent_instance;
GMutex mutex;
gboolean use_time;
- gboolean use_color;
};
G_DEFINE_TYPE (GsDebug, gs_debug, G_TYPE_OBJECT)
@@ -91,32 +90,38 @@ gs_log_writer_console (GLogLevelFlags log_level,
for (guint i = domain->len; i < 3; i++)
g_string_append (domain, " ");
- /* to file */
- if (!debug->use_color) {
- if (tmp != NULL)
- g_print ("%s ", tmp);
- g_print ("%s ", domain->str);
- g_print ("%s\n", log_message);
-
- /* to screen */
- } else {
- switch (log_level) {
- case G_LOG_LEVEL_ERROR:
- case G_LOG_LEVEL_CRITICAL:
- case G_LOG_LEVEL_WARNING:
+ switch (log_level) {
+ case G_LOG_LEVEL_ERROR:
+ case G_LOG_LEVEL_CRITICAL:
+ case G_LOG_LEVEL_WARNING:
+ /* to screen */
+ if (isatty (fileno (stderr)) == 1) {
/* critical in red */
if (tmp != NULL)
- g_print ("%c[%dm%s ", 0x1B, 32, tmp);
+ g_printerr ("%c[%dm%s ", 0x1B, 32, tmp);
+ g_printerr ("%s ", domain->str);
+ g_printerr ("%c[%dm%s\n%c[%dm", 0x1B, 31, log_message, 0x1B, 0);
+ } else { /* to file */
+ if (tmp != NULL)
+ g_print ("%s ", tmp);
g_print ("%s ", domain->str);
- g_print ("%c[%dm%s\n%c[%dm", 0x1B, 31, log_message, 0x1B, 0);
- break;
- default:
+ g_print ("%s\n", log_message);
+ }
+ break;
+ default:
+ /* to screen */
+ if (isatty (fileno (stdout)) == 1) {
/* debug in blue */
if (tmp != NULL)
g_print ("%c[%dm%s ", 0x1B, 32, tmp);
g_print ("%s ", domain->str);
g_print ("%c[%dm%s\n%c[%dm", 0x1B, 34, log_message, 0x1B, 0);
break;
+ } else { /* to file */
+ if (tmp != NULL)
+ g_print ("%s ", tmp);
+ g_print ("%s ", domain->str);
+ g_print ("%s\n", log_message);
}
}
@@ -179,7 +184,6 @@ gs_debug_init (GsDebug *debug)
{
g_mutex_init (&debug->mutex);
debug->use_time = g_getenv ("GS_DEBUG_NO_TIME") == NULL;
- debug->use_color = (isatty (fileno (stdout)) == 1);
g_log_set_writer_func (gs_debug_log_writer,
g_object_ref (debug),
(GDestroyNotify) g_object_unref);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]