[nautilus] debug: add a new, simpler nautilus-debug module, based on Empathy's
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] debug: add a new, simpler nautilus-debug module, based on Empathy's
- Date: Thu, 2 Dec 2010 13:31:08 +0000 (UTC)
commit 695b2d933406b039fb46592b90b5f844d381490c
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Thu Dec 2 13:52:39 2010 +0100
debug: add a new, simpler nautilus-debug module, based on Empathy's
We lose dumping the log to a file automatically, but we gain a lot in
flexibility.
configure.in | 18 ++++
libnautilus-private/nautilus-debug.c | 155 ++++++++++++++++++++++++++++++++++
libnautilus-private/nautilus-debug.h | 88 +++++++++++++++++++
3 files changed, 261 insertions(+), 0 deletions(-)
---
diff --git a/configure.in b/configure.in
index 95192fb..82ce7ab 100644
--- a/configure.in
+++ b/configure.in
@@ -87,6 +87,24 @@ AM_CONDITIONAL(ENABLE_PROFILER, test "x$ENABLE_PROFILER" = "x1")
dnl ==========================================================================
+AC_ARG_ENABLE(debug,
+ AC_HELP_STRING([--disable-debug],[Disable debugging code]),
+ [
+ case "${enableval}" in
+ yes|no) enable_debug="${enableval}" ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
+ esac
+ ],
+ [enable_debug=yes])
+
+if test "$enable_debug" = yes; then
+ AC_DEFINE(ENABLE_DEBUG, [], [Enable debug code])
+else
+ enable_debug=no
+fi
+
+dnl ==========================================================================
+
AC_CHECK_PROGS(PERL, perl5 perl)
AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
diff --git a/libnautilus-private/nautilus-debug.c b/libnautilus-private/nautilus-debug.c
new file mode 100644
index 0000000..88fe319
--- /dev/null
+++ b/libnautilus-private/nautilus-debug.c
@@ -0,0 +1,155 @@
+/*
+ * nautilus-debug: debug loggers for nautilus
+ *
+ * Copyright (C) 2007 Collabora Ltd.
+ * Copyright (C) 2007 Nokia Corporation
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Based on Empathy's empathy-debug.
+ */
+
+#include <stdarg.h>
+
+#include <glib.h>
+
+#include "nautilus-debug.h"
+
+#include "nautilus-file.h"
+
+#ifdef ENABLE_DEBUG
+
+static DebugFlags flags = 0;
+static gboolean initialized = FALSE;
+
+static GDebugKey keys[] = {
+ { "Application", NAUTILUS_DEBUG_APPLICATION },
+ { "DirectoryView", NAUTILUS_DEBUG_DIRECTORY_VIEW },
+ { "IconContainer", NAUTILUS_DEBUG_ICON_CONTAINER },
+ { "ListView", NAUTILUS_DEBUG_LIST_VIEW },
+ { "Mime", NAUTILUS_DEBUG_MIME },
+ { "Places", NAUTILUS_DEBUG_PLACES },
+ { "Smclient", NAUTILUS_DEBUG_SMCLIENT },
+ { "Window", NAUTILUS_DEBUG_WINDOW },
+ { 0, }
+};
+
+void
+nautilus_debug_set_flags_from_env ()
+{
+ guint nkeys;
+ const gchar *flags_string;
+
+ for (nkeys = 0; keys[nkeys].value; nkeys++);
+
+ flags_string = g_getenv ("NAUTILUS_DEBUG");
+
+ if (flags_string)
+ nautilus_debug_set_flags (g_parse_debug_string (flags_string, keys, nkeys));
+
+ initialized = TRUE;
+}
+
+void
+nautilus_debug_set_flags (DebugFlags new_flags)
+{
+ flags |= new_flags;
+ initialized = TRUE;
+}
+
+gboolean
+nautilus_debug_flag_is_set (DebugFlags flag)
+{
+ return flag & flags;
+}
+
+void
+nautilus_debug (DebugFlags flag,
+ const gchar *format,
+ ...)
+{
+ va_list args;
+ va_start (args, format);
+ nautilus_debug_valist (flag, format, args);
+ va_end (args);
+}
+
+void
+nautilus_debug_valist (DebugFlags flag,
+ const gchar *format,
+ va_list args)
+{
+ if (G_UNLIKELY(!initialized))
+ nautilus_debug_set_flags_from_env ();
+
+ if (flag & flags)
+ g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
+}
+
+static void
+nautilus_debug_files_valist (DebugFlags flag,
+ GList *files,
+ const gchar *format,
+ va_list args)
+{
+ NautilusFile *file;
+ GList *l;
+ gchar *uri, *msg;
+
+ if (G_UNLIKELY (!initialized))
+ nautilus_debug_set_flags_from_env ();
+
+ msg = g_strdup_vprintf (format, args);
+
+ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s:", msg);
+
+ for (l = files; l != NULL; l = l->next)
+ {
+ file = l->data;
+ uri = nautilus_file_get_uri (file);
+
+ if (nautilus_file_is_gone (file)) {
+ gchar *new_uri;
+
+ /* Hack: this will create an invalid URI, but it's for
+ * display purposes only.
+ */
+ new_uri = g_strconcat (uri ? uri : "", " (gone)", NULL);
+ g_free (uri);
+ uri = new_uri;
+ }
+
+ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, " %s", uri);
+ g_free (uri);
+ }
+
+ g_free (msg);
+}
+
+void
+nautilus_debug_files (DebugFlags flag,
+ GList *files,
+ const gchar *format,
+ ...)
+{
+ va_list args;
+
+ va_start (args, format);
+ nautilus_debug_files_valist (flags, files, format, args);
+ va_end (args);
+}
+
+#endif /* ENABLE_DEBUG */
diff --git a/libnautilus-private/nautilus-debug.h b/libnautilus-private/nautilus-debug.h
new file mode 100644
index 0000000..becae88
--- /dev/null
+++ b/libnautilus-private/nautilus-debug.h
@@ -0,0 +1,88 @@
+/*
+ * nautilus-debug: debug loggers for nautilus
+ *
+ * Copyright (C) 2007 Collabora Ltd.
+ * Copyright (C) 2007 Nokia Corporation
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Based on Empathy's empathy-debug.
+ */
+
+#ifndef __NAUTILUS_DEBUG_H__
+#define __NAUTILUS_DEBUG_H__
+
+#include <config.h>
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#ifdef ENABLE_DEBUG
+
+typedef enum {
+ NAUTILUS_DEBUG_APPLICATION = 1 << 1,
+ NAUTILUS_DEBUG_DIRECTORY_VIEW = 1 << 2,
+ NAUTILUS_DEBUG_ICON_CONTAINER = 1 << 3,
+ NAUTILUS_DEBUG_LIST_VIEW = 1 << 4,
+ NAUTILUS_DEBUG_MIME = 1 << 5,
+ NAUTILUS_DEBUG_PLACES = 1 << 6,
+ NAUTILUS_DEBUG_SMCLIENT = 1 << 7,
+ NAUTILUS_DEBUG_WINDOW = 1 << 8,
+} DebugFlags;
+
+void nautilus_debug_set_flags_from_env (void);
+void nautilus_debug_set_flags (DebugFlags flags);
+gboolean nautilus_debug_flag_is_set (DebugFlags flag);
+
+void nautilus_debug_valist (DebugFlags flag,
+ const gchar *format, va_list args);
+
+void nautilus_debug (DebugFlags flag, const gchar *format, ...)
+ G_GNUC_PRINTF (2, 3);
+
+void nautilus_debug_files (DebugFlags flag, GList *files,
+ const gchar *format, ...) G_GNUC_PRINTF (3, 4);
+
+#ifdef DEBUG_FLAG
+
+#define DEBUG(format, ...) \
+ nautilus_debug (DEBUG_FLAG, "%s: %s: " format, G_STRFUNC, G_STRLOC, \
+ ##__VA_ARGS__)
+
+#define DEBUG_FILES(files, format, ...) \
+ nautilus_debug_files (DEBUG_FLAG, files, "%s:" format, G_STRFUNC, \
+ ##__VA_ARGS__)
+
+#define DEBUGGING nautilus_debug_flag_is_set(DEBUG_FLAG)
+
+#endif /* DEBUG_FLAG */
+
+#else /* ENABLE_DEBUG */
+
+#ifdef DEBUG_FLAG
+
+#define DEBUG(format, ...) \
+ G_STMT_START { } G_STMT_END
+
+#define DEBUGGING 0
+
+#endif /* DEBUG_FLAG */
+
+#endif /* ENABLE_DEBUG */
+
+G_END_DECLS
+
+#endif /* __NAUTILUS_DEBUG_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]