I run a lot of commands from the command line. Many of the graphical applications such as gedit use glib. I get a ton of spam on the terminal when I run them that look like:

(gedit:5700): Gtk-WARNING **:  ...

I've written a patch to allow the user to skip these messages if desired.

What you do is

  patch -Np2  ../glib.patch
  Continue with regular glib build/install

This patch should change nothing unless the environment variable GLIB_LOG_LEVEL is set. The values are numeric:

0  Emergency
1  Alert
2  Critical
3  Error
4  Warning
5  Notice
6  Info
7  Debug

So if you want to disable messages at the Warning level or above, you use:

export GLIB_LOG_LEVEL=4

I'm asking for feedback to see if this is worth putting in BLFS or perhaps offering it upstream.

Feedback welcome.

  -- Bruce
--- glib2/glib-2.54.0/glib/gmessages.c	2017-08-19 08:39:20.000000000 -0500
+++ glib2-devel/glib-2.54.0/glib/gmessages.c	2017-10-13 13:55:31.929873316 -0500
@@ -1220,6 +1220,29 @@
 
 static GSList *expected_messages = NULL;
 
+int 
+skip_message( GLogLevelFlags log_level ); // Declare before definition
+
+int 
+skip_message( GLogLevelFlags log_level )
+{
+  char* user_log_level;
+  int   user_log_int;
+  int   skip = FALSE;
+
+  user_log_level = getenv( "GLIB_LOG_LEVEL" );
+  //fprintf( stderr, "GLIB_LOG_LEVEL=%s\n", user_log_level);
+
+  user_log_int = ( user_log_level != NULL ) ? atoi( user_log_level ) : 0;
+  user_log_int = ( user_log_int   != 0    ) ? 1 << user_log_int      : 0;
+  //fprintf( stderr, "user_log_int=%i\n", user_log_int);
+  //fprintf( stderr, "log_level=%i\n"   , log_level);
+  
+  if ( user_log_int >= log_level ) skip = TRUE;
+ 
+  return skip;
+}   
+
 /**
  * g_logv:
  * @log_domain: (nullable): the log domain, or %NULL for the default ""
@@ -1255,6 +1278,13 @@
   if (!log_level)
     return;
 
+  /* Don't output messages not wanted by the user */
+  if ( skip_message( log_level ) )
+  { 
+     //fprintf( stderr, "skipping\n" );
+     return;
+  }
+
   if (log_level & G_LOG_FLAG_RECURSION)
     {
       /* we use a stack buffer of fixed size, since we're likely
@@ -1685,6 +1715,13 @@
   GLogField *fields_allocated = NULL;
   GArray *array = NULL;
 
+  /* Don't output messages not wanted by the user */
+  if ( skip_message( log_level ) )
+  { 
+     //fprintf( stderr, "g_log_structured skipping\n" );
+     return;
+  }
+
   va_start (args, log_level);
 
   /* MESSAGE and PRIORITY are a given */
-- 
http://lists.linuxfromscratch.org/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to