On 12/28/20 1:28 PM, Michael Eager wrote:
> I'm running a wxPython program using a wx.ScrolledWindow. I'm getting a
> lot of the following console messages: ...
On 12/29/20 6:30 AM, Marian Beermann wrote:
> One can install a glib log writer (through g_log_set_writer_func via
> ctypes) to discard or log GTK's noise somewhere else.
>
> -Marian
I created a library which installs a glib_log_writer which filters out
the unwanted messages while allowing other messages to be logged
normally. This could be generalized to pass a list of messages from the
wxpython application to the filter instead of hard-coding the text.
---
In the wxpython application:
import ctypes
def SetGtkLogger(quiet):
mygtk = ctypes.cdll.LoadLibrary('./libfiltergtk.so')
mygtk.setgtklogger(quiet)
def main(argv):
SetGtkLogger(1)
...
---
$ cat filtergtk.c
#include <string.h>
#include <glib.h>
#include <stdio.h>
//#define DEBUG
void
print_fields (const GLogField *fields,
gsize n_fields)
{
#ifdef DEBUG
int i;
for (i = 0; i < n_fields; i++)
printf ("[%d]: ('%s':'%s')\n", i, fields[i].key,
fields[i].value);
#endif
}
static GLogWriterOutput
mylogwriter (GLogLevelFlags log_level,
const GLogField *fields,
gsize n_fields,
gpointer user_data)
{
print_fields (fields, n_fields);
if ((log_level == G_LOG_LEVEL_CRITICAL) &&
strstr (fields[4].value, "gtk_box_gadget_distribute"))
return G_LOG_WRITER_HANDLED;
return g_log_writer_default (log_level, fields, n_fields,
user_data);
}
void
setgtklogger (int quiet)
{
g_log_set_writer_func (mylogwriter, NULL, NULL);
if (!quiet)
g_message ("Installed local gtk message writer");
}
---
$ cat Makefile
# makefile for gtk message filter library
#
#
libfiltergtk.so: filtergtk.o
gcc -shared -o libfiltergtk.so -lglib-2.0 filtergtk.o
filtergtk.o: filtergtk.c
gcc -c -fPIC -I /usr/include/glib-2.0/ -I
/usr/lib64/glib-2.0/include/ filtergtk.c
clean:
rm -f filtergtk.o libfiltergtk.so
[Watch out for email replacing tabs with blanks in the makefile.]
--
Michael Eager