Allow logging only specific debug topics

While debugging a focus problem, I noticed that Mutter had exactly
the debug statements I wanted under the META_DEBUG_FOCUS topic.
However, calling meta_set_verbose (true) results in enormous amounts
of other messages, and it's inconvenient to filter after having
started mutter.

This patch allows one to call Meta.add_debug_topic(Meta.DebugTopic.FOCUS)
from a console, and get just what one wants.

https://bugzilla.gnome.org/show_bug.cgi?id=620359
This commit is contained in:
Colin Walters 2010-06-02 09:26:53 -04:00
parent 91d82bf8c7
commit 343474a570
2 changed files with 76 additions and 31 deletions

View File

@ -40,6 +40,12 @@
#include <X11/Xlib.h> /* must explicitly be included for Solaris; #326746 */
#include <X11/Xutil.h> /* Just for the definition of the various gravities */
static void
meta_topic_real_valist (MetaDebugTopic topic,
const char *format,
va_list args);
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
void
@ -71,7 +77,7 @@ meta_print_backtrace (void)
}
#endif
static gboolean is_verbose = FALSE;
static gint verbose_topics = 0;
static gboolean is_debugging = FALSE;
static gboolean replace_current = FALSE;
static int no_prefix = 0;
@ -128,7 +134,7 @@ ensure_logfile (void)
gboolean
meta_is_verbose (void)
{
return is_verbose;
return verbose_topics != 0;
}
void
@ -142,7 +148,47 @@ meta_set_verbose (gboolean setting)
ensure_logfile ();
#endif
is_verbose = setting;
if (setting)
meta_add_verbose_topic (META_DEBUG_VERBOSE);
else
meta_remove_verbose_topic (META_DEBUG_VERBOSE);
}
/**
* meta_add_verbose_topic:
* @topic: Topic for which logging will be started
*
* Ensure log messages for the given topic @topic
* will be printed.
*/
void
meta_add_verbose_topic (MetaDebugTopic topic)
{
if (verbose_topics == META_DEBUG_VERBOSE)
return;
if (topic == META_DEBUG_VERBOSE)
verbose_topics = META_DEBUG_VERBOSE;
else
verbose_topics |= topic;
}
/**
* meta_remove_verbose_topic:
* @topic: Topic for which logging will be stopped
*
* Stop printing log messages for the given topic @topic. Note
* that this method does not stack with meta_add_verbose_topic();
* i.e. if two calls to meta_add_verbose_topic() for the same
* topic are made, one call to meta_remove_verbose_topic() will
* remove it.
*/
void
meta_remove_verbose_topic (MetaDebugTopic topic)
{
if (topic == META_DEBUG_VERBOSE)
verbose_topics = 0;
else
verbose_topics &= ~topic;
}
gboolean
@ -250,27 +296,10 @@ void
meta_verbose_real (const char *format, ...)
{
va_list args;
gchar *str;
FILE *out;
g_return_if_fail (format != NULL);
if (!is_verbose)
return;
va_start (args, format);
str = g_strdup_vprintf (format, args);
meta_topic_real_valist (META_DEBUG_VERBOSE, format, args);
va_end (args);
out = logfile ? logfile : stderr;
if (no_prefix == 0)
utf8_fputs ("Window manager: ", out);
utf8_fputs (str, out);
fflush (out);
g_free (str);
}
#endif /* WITH_VERBOSE_MODE */
@ -324,6 +353,8 @@ topic_name (MetaDebugTopic topic)
return "COMPOSITOR";
case META_DEBUG_EDGE_RESISTANCE:
return "EDGE_RESISTANCE";
case META_DEBUG_VERBOSE:
return "VERBOSE";
}
return "WM";
@ -331,23 +362,22 @@ topic_name (MetaDebugTopic topic)
static int sync_count = 0;
void
meta_topic_real (MetaDebugTopic topic,
static void
meta_topic_real_valist (MetaDebugTopic topic,
const char *format,
...)
va_list args)
{
va_list args;
gchar *str;
FILE *out;
g_return_if_fail (format != NULL);
if (!is_verbose)
if (verbose_topics == 0
|| (topic == META_DEBUG_VERBOSE && verbose_topics != META_DEBUG_VERBOSE)
|| (!(verbose_topics & topic)))
return;
va_start (args, format);
str = g_strdup_vprintf (format, args);
va_end (args);
out = logfile ? logfile : stderr;
@ -366,6 +396,18 @@ meta_topic_real (MetaDebugTopic topic,
g_free (str);
}
void
meta_topic_real (MetaDebugTopic topic,
const char *format,
...)
{
va_list args;
va_start (args, format);
meta_topic_real_valist (topic, format, args);
va_end (args);
}
#endif /* WITH_VERBOSE_MODE */
void

View File

@ -51,6 +51,7 @@ void meta_fatal (const char *format,
typedef enum
{
META_DEBUG_VERBOSE = -1,
META_DEBUG_FOCUS = 1 << 0,
META_DEBUG_WORKAREA = 1 << 1,
META_DEBUG_STACK = 1 << 2,
@ -78,6 +79,8 @@ typedef enum
void meta_topic_real (MetaDebugTopic topic,
const char *format,
...) G_GNUC_PRINTF (2, 3);
void meta_add_verbose_topic (MetaDebugTopic topic);
void meta_remove_verbose_topic (MetaDebugTopic topic);
void meta_push_no_msg_prefix (void);
void meta_pop_no_msg_prefix (void);