[couchdb-glib] Conditionally log debugging messages
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [couchdb-glib] Conditionally log debugging messages
- Date: Mon, 18 Jan 2010 12:40:49 +0000 (UTC)
commit f8c7ed7b4f92c8365a3d65eac98d72231e2d3d30
Author: Adi Roiban <adiroiban ubuntu com>
Date: Mon Jan 18 13:40:21 2010 +0100
Conditionally log debugging messages
couchdb-glib/couchdb-session.c | 46 ++++++++++++++++++++++++++++++++-------
1 files changed, 37 insertions(+), 9 deletions(-)
---
diff --git a/couchdb-glib/couchdb-session.c b/couchdb-glib/couchdb-session.c
index 51be181..1216c09 100644
--- a/couchdb-glib/couchdb-session.c
+++ b/couchdb-glib/couchdb-session.c
@@ -59,6 +59,16 @@ enum {
PROP_URI
};
+#ifdef DEBUG_MESSAGES
+#define COUCHDB_ENV_DEBUG_MESSAGES "COUCHDB_DEBUG_MESSAGES"
+
+static void debug_print_headers (const char *name, const char *value,
+ gpointer user_data);
+static void debug_message (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message, gpointer user_data);
+#endif
+
static void
couchdb_session_finalize (GObject *object)
{
@@ -200,7 +210,9 @@ couchdb_session_init (CouchdbSession *couchdb)
couchdb->priv->credentials = NULL;
- soup_session_add_feature_by_type (couchdb->priv->http_session, SOUP_TYPE_LOGGER);
+#ifdef DEBUG_MESSAGES
+ g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, debug_message, NULL);
+#endif
}
CouchdbSession *
@@ -529,7 +541,7 @@ add_oauth_signature (CouchdbSession *couchdb, SoupMessage *http_message, const c
int i;
params = g_strsplit (parsed_url[1], "&", 0);
-#ifdef DEBUG_OAUTH
+#ifdef DEBUG_MESSAGES
g_debug ("Parsing %s", parsed_url[1]);
#endif
for (i = 0; params[i] != NULL; i++) {
@@ -607,12 +619,6 @@ parse_json_response (CouchdbSession *couchdb, JsonParser *json_parser, SoupMessa
return success;
}
-static void
-debug_print_headers (const char *name, const char *value, gpointer user_data)
-{
- g_print ("\t%s: %s\n", name, value);
-}
-
gboolean
couchdb_session_send_message (CouchdbSession *couchdb, const char *method, const char *url, const char *body, JsonParser *parser, GError **error)
{
@@ -640,10 +646,11 @@ couchdb_session_send_message (CouchdbSession *couchdb, const char *method, const
}
g_debug ("Sending %s to %s... with headers\n: ", method, url);
+#ifdef DEBUG_MESSAGES
soup_message_headers_foreach (http_message->request_headers,
(SoupMessageHeadersForeachFunc) debug_print_headers,
NULL);
-
+#endif
status = soup_session_send_message (couchdb->priv->http_session, http_message);
if (SOUP_STATUS_IS_SUCCESSFUL (status)) {
if (parser != NULL)
@@ -654,3 +661,24 @@ couchdb_session_send_message (CouchdbSession *couchdb, const char *method, const
return FALSE;
}
}
+
+#ifdef DEBUG_MESSAGES
+static void
+debug_print_headers (const char *name, const char *value, gpointer user_data)
+{
+ g_debug ("\t%s: %s\n", name, value);
+}
+
+static void
+debug_message (const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer user_data)
+{
+ gchar* couchdb_env_debug_messages;
+
+ couchdb_env_debug_messages = g_getenv(COUCHDB_ENV_DEBUG_MESSAGES);
+ if (couchdb_env_debug_messages != NULL) {
+ g_printf ("couchdb-glib:DEBUG: %s\n", message);
+ }
+}
+#endif
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]