[mutter/wip/display-no-wayland: 2/33] Improve handling of warnings and criticals



commit f3d1653f13f05bbcdda932310daf31f57d61aa5e
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Mon May 20 00:12:09 2013 +0200

    Improve handling of warnings and criticals
    
    Instead of squash everything into "window manager warnings",
    let the glib log framework handle Mutter (and other) warnings.
    META_USE_LOGFILE support is preserved by rerouting warnings
    in our domain.
    This way we get process name and PID, nice CRITICAL/WARNING/ERROR
    instead of a number, and the ability for plugins to override
    the log handler. For example gnome-shell uses this to output
    a JS backtrace.

 src/Makefile.am |    2 +-
 src/core/main.c |   36 +----------------
 src/core/util.c |  113 ++++++++++++++++++++++++++-----------------------------
 src/meta/util.h |    2 +
 4 files changed, 58 insertions(+), 95 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 5a20ef1..5f2b10d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,7 +19,7 @@ INCLUDES=                                                             \
        -DMUTTER_LOCALEDIR=\"$(prefix)/@DATADIRNAME@/locale\"           \
        -DMUTTER_PKGDATADIR=\"$(pkgdatadir)\"                           \
        -DMUTTER_DATADIR=\"$(datadir)\"                                 \
-       -DG_LOG_DOMAIN=\"mutter\"                                       \
+       -DG_LOG_DOMAIN=\"Mutter\"                                       \
        -DSN_API_NOT_YET_FROZEN=1                                       \
        -DMUTTER_MAJOR_VERSION=$(MUTTER_MAJOR_VERSION)                  \
        -DMUTTER_MINOR_VERSION=$(MUTTER_MINOR_VERSION)                  \
diff --git a/src/core/main.c b/src/core/main.c
index 767a8b8..567e988 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -94,26 +94,6 @@ static void prefs_changed_callback (MetaPreference pref,
                                     gpointer       data);
 
 /**
- * log_handler:
- * @log_domain: the domain the error occurred in (we ignore this)
- * @log_level: the log level so that we can filter out less
- *             important messages
- * @message: the message to log
- * @user_data: arbitrary data (we ignore this)
- *
- * Prints log messages. If Mutter was compiled with backtrace support,
- * also prints a backtrace (see meta_print_backtrace()).
- */
-static void
-log_handler (const gchar   *log_domain,
-             GLogLevelFlags log_level,
-             const gchar   *message,
-             gpointer       user_data)
-{
-  meta_warning ("Log level %d: %s\n", log_level, message);
-}
-
-/**
  * meta_print_compilation_info:
  *
  * Prints a list of which configure script options were used to
@@ -411,6 +391,8 @@ meta_init (void)
     g_printerr ("Failed to register SIGTERM handler: %s\n",
                g_strerror (errno));
 
+  meta_debug_init ();
+
   if (g_getenv ("MUTTER_VERBOSE"))
     meta_set_verbose (TRUE);
   if (g_getenv ("MUTTER_DEBUG"))
@@ -496,24 +478,10 @@ meta_register_with_session (void)
 int
 meta_run (void)
 {
-  const gchar *log_domains[] = {
-    NULL, G_LOG_DOMAIN, "Gtk", "Gdk", "GLib",
-    "Pango", "GLib-GObject", "GThread"
-  };
-  guint i;
-
   /* Load prefs */
   meta_prefs_init ();
   meta_prefs_add_listener (prefs_changed_callback, NULL);
 
-  for (i=0; i<G_N_ELEMENTS(log_domains); i++)
-    g_log_set_handler (log_domains[i],
-                       G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
-                       log_handler, NULL);
-
-  if (g_getenv ("MUTTER_G_FATAL_WARNINGS") != NULL)
-    g_log_set_always_fatal (G_LOG_LEVEL_MASK);
-  
   meta_ui_set_current_theme (meta_prefs_get_theme ());
 
   /* Try to find some theme that'll work if the theme preference
diff --git a/src/core/util.c b/src/core/util.c
index 92a33e4..6c004e1 100644
--- a/src/core/util.c
+++ b/src/core/util.c
@@ -389,92 +389,86 @@ meta_topic_real (MetaDebugTopic topic,
 }
 #endif /* WITH_VERBOSE_MODE */
 
+#ifdef WITH_VERBOSE_MODE
+static void
+logfile_log_handler (const gchar *log_domain,
+                     GLogLevelFlags log_level,
+                     const gchar *message,
+                     gpointer user_data)
+{
+  switch (log_level & G_LOG_LEVEL_MASK) {
+  case G_LOG_LEVEL_ERROR:
+    utf8_fputs ("ERROR: ", logfile);
+    break;
+
+  case G_LOG_LEVEL_CRITICAL:
+    utf8_fputs ("CRITICAL: ", logfile);
+    break;
+
+  case G_LOG_LEVEL_WARNING:
+    utf8_fputs ("WARNING: ", logfile);
+    break;
+
+  default:
+    /* the other levels don't go through
+       g_log, they go directly to the log file */
+    ;
+  }
+
+  utf8_fputs (message, logfile);
+}
+
+void
+meta_debug_init (void)
+{
+  ensure_logfile ();
+
+  if (logfile)
+    g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK,
+                       logfile_log_handler, NULL);
+}
+#else
+void
+meta_debug_init (void)
+{
+}
+#endif
+
 void
 meta_bug (const char *format, ...)
 {
   va_list args;
-  gchar *str;
-  FILE *out;
 
   g_return_if_fail (format != NULL);
-  
+
   va_start (args, format);
-  str = g_strdup_vprintf (format, args);
+  g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
   va_end (args);
-
-#ifdef WITH_VERBOSE_MODE
-  out = logfile ? logfile : stderr;
-#else
-  out = stderr;
-#endif
-
-  if (no_prefix == 0)
-    utf8_fputs (_("Bug in window manager: "), out);
-  utf8_fputs (str, out);
-
-  fflush (out);
-  
-  g_free (str);
-  
-  /* stop us in a debugger */
-  abort ();
 }
 
 void
 meta_warning (const char *format, ...)
 {
   va_list args;
-  gchar *str;
-  FILE *out;
-  
+
   g_return_if_fail (format != NULL);
-  
+
   va_start (args, format);
-  str = g_strdup_vprintf (format, args);
+  g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
   va_end (args);
-
-#ifdef WITH_VERBOSE_MODE
-  out = logfile ? logfile : stderr;
-#else
-  out = stderr;
-#endif
-
-  if (no_prefix == 0)
-    utf8_fputs (_("Window manager warning: "), out);
-  utf8_fputs (str, out);
-
-  fflush (out);
-  
-  g_free (str);
 }
 
 void
 meta_fatal (const char *format, ...)
 {
   va_list args;
-  gchar *str;
-  FILE *out;
-  
+
   g_return_if_fail (format != NULL);
-  
+
   va_start (args, format);
-  str = g_strdup_vprintf (format, args);
+  g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, args);
   va_end (args);
 
-#ifdef WITH_VERBOSE_MODE
-  out = logfile ? logfile : stderr;
-#else
-  out = stderr;
-#endif
-
-  if (no_prefix == 0)
-    utf8_fputs (_("Window manager error: "), out);
-  utf8_fputs (str, out);
-
-  fflush (out);
-  
-  g_free (str);
-
   meta_exit (META_EXIT_ERROR);
 }
 
@@ -495,7 +489,6 @@ meta_pop_no_msg_prefix (void)
 void
 meta_exit (MetaExitCode code)
 {
-  
   exit (code);
 }
 
diff --git a/src/meta/util.h b/src/meta/util.h
index be87190..32ddddc 100644
--- a/src/meta/util.h
+++ b/src/meta/util.h
@@ -109,6 +109,8 @@ void meta_topic_real      (MetaDebugTopic topic,
 void meta_add_verbose_topic    (MetaDebugTopic topic);
 void meta_remove_verbose_topic (MetaDebugTopic topic);
 
+void meta_debug_init      (void);
+
 void meta_push_no_msg_prefix (void);
 void meta_pop_no_msg_prefix  (void);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]