[evolution-data-server] Introduce e_util_debug_print() for consistent debug print form
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Introduce e_util_debug_print() for consistent debug print form
- Date: Fri, 6 Apr 2018 14:07:32 +0000 (UTC)
commit 3c2b5a90d037c459bd272796297b72679b4013af
Author: Milan Crha <mcrha redhat com>
Date: Fri Apr 6 16:07:18 2018 +0200
Introduce e_util_debug_print() for consistent debug print form
src/libedataserver/e-data-server-util.c | 81 +++++++++++++++++++-
src/libedataserver/e-data-server-util.h | 6 ++
.../e-credentials-prompter-impl-oauth2.c | 2 +-
.../module-gnome-online-accounts.c | 25 +------
4 files changed, 85 insertions(+), 29 deletions(-)
---
diff --git a/src/libedataserver/e-data-server-util.c b/src/libedataserver/e-data-server-util.c
index 703413d..5f2c76b 100644
--- a/src/libedataserver/e-data-server-util.c
+++ b/src/libedataserver/e-data-server-util.c
@@ -2781,19 +2781,92 @@ void
e_source_registry_debug_print (const gchar *format,
...)
{
- GString *str;
va_list args;
if (!e_source_registry_debug_enabled ())
return;
- str = g_string_new ("");
+ va_start (args, format);
+ e_util_debug_printv ("ESR", format, args);
+ va_end (args);
+}
+
+/**
+ * e_util_debug_print:
+ * @domain: a debug domain
+ * @format: a printf-like format
+ * @...: arguments for the @format
+ *
+ * Prints a text according to @format and its arguments to stdout
+ * prefixed with @domain in brackets [] and the current date and time.
+ * This function doesn't check whether the logging is enabled, it's up
+ * to the caller to determine it, the function only prints the information
+ * in a consistent format:
+ * [domain] YYYY-MM-DD hh:mm:ss.ms - format
+ *
+ * Since: 3.30
+ *
+ * See: e_util_debug_printv()
+ **/
+void
+e_util_debug_print (const gchar *domain,
+ const gchar *format,
+ ...)
+{
+ va_list args;
va_start (args, format);
- g_string_vprintf (str, format, args);
+ e_util_debug_printv (domain, format, args);
va_end (args);
+}
- g_print ("%s", str->str);
+/**
+ * e_util_debug_printv:
+ * @domain: a debug domain
+ * @format: a printf-like format
+ * @args: arguments for the @format
+ *
+ * Prints a text according to @format and its @args to stdout
+ * prefixed with @domain in brackets [] and the current date and time.
+ * This function doesn't check whether the logging is enabled, it's up
+ * to the caller to determine it, the function only prints the information
+ * in a consistent form:
+ * [@domain] YYYY-MM-DD hh:mm:ss.ms - @format
+ *
+ * Since: 3.30
+ *
+ * See: e_util_debug_print()
+ **/
+void
+e_util_debug_printv (const gchar *domain,
+ const gchar *format,
+ va_list args)
+{
+ GString *str;
+ GDateTime *dt;
+
+ if (!domain)
+ domain = "???";
+
+ str = g_string_new ("");
+ g_string_vprintf (str, format, args);
+ dt = g_date_time_new_now_local ();
+
+ if (dt) {
+ g_print ("[%s] %04d-%02d-%02d %02d:%02d:%02d.%03d - %s",
+ domain,
+ g_date_time_get_year (dt),
+ g_date_time_get_month (dt),
+ g_date_time_get_day_of_month (dt),
+ g_date_time_get_hour (dt),
+ g_date_time_get_minute (dt),
+ g_date_time_get_second (dt),
+ g_date_time_get_microsecond (dt) / 1000,
+ str->str);
+ g_date_time_unref (dt);
+ } else {
+ g_print ("[%s] %s", domain, str->str);
+ }
g_string_free (str, TRUE);
}
diff --git a/src/libedataserver/e-data-server-util.h b/src/libedataserver/e-data-server-util.h
index 20d203e..02d4a5e 100644
--- a/src/libedataserver/e-data-server-util.h
+++ b/src/libedataserver/e-data-server-util.h
@@ -256,6 +256,12 @@ void e_data_server_util_set_dbus_call_timeout
gboolean e_source_registry_debug_enabled (void);
void e_source_registry_debug_print (const gchar *format,
...) G_GNUC_PRINTF (1, 2);
+void e_util_debug_print (const gchar *domain,
+ const gchar *format,
+ ...) G_GNUC_PRINTF (2, 3);
+void e_util_debug_printv (const gchar *domain,
+ const gchar *format,
+ va_list args);
/**
* ETypeFunc:
diff --git a/src/libedataserverui/e-credentials-prompter-impl-oauth2.c
b/src/libedataserverui/e-credentials-prompter-impl-oauth2.c
index bb6698e..7babc4b 100644
--- a/src/libedataserverui/e-credentials-prompter-impl-oauth2.c
+++ b/src/libedataserverui/e-credentials-prompter-impl-oauth2.c
@@ -369,7 +369,7 @@ cpi_oauth2_document_load_changed_cb (WebKitWebView *web_view,
return;
if (cpi_oauth2_get_debug ()) {
- g_print ("[OAuth2] Loaded URI: '%s'\n", uri);
+ e_util_debug_print ("OAuth2", "Loaded URI: '%s'\n", uri);
}
g_return_if_fail (prompter_oauth2->priv->service != NULL);
diff --git a/src/modules/gnome-online-accounts/module-gnome-online-accounts.c
b/src/modules/gnome-online-accounts/module-gnome-online-accounts.c
index d8767ce..1d5672d 100644
--- a/src/modules/gnome-online-accounts/module-gnome-online-accounts.c
+++ b/src/modules/gnome-online-accounts/module-gnome-online-accounts.c
@@ -51,9 +51,7 @@ e_goa_debug_printf (const gchar *format,
...)
{
static gint goa_debug = -1;
- GString *str;
va_list args;
- GDateTime *dt;
if (goa_debug == -1)
goa_debug = g_strcmp0 (g_getenv ("GOA_DEBUG"), "1") == 0 ? 1 : 0;
@@ -61,30 +59,9 @@ e_goa_debug_printf (const gchar *format,
if (!goa_debug)
return;
- str = g_string_new ("");
-
va_start (args, format);
- g_string_vprintf (str, format, args);
+ e_util_debug_printv ("EDS-GOA", format, args);
va_end (args);
-
- dt = g_date_time_new_now_local ();
-
- if (dt) {
- g_print ("[EDS-GOA] %04d-%02d-%02d %02d:%02d:%02d.%03d - %s",
- g_date_time_get_year (dt),
- g_date_time_get_month (dt),
- g_date_time_get_day_of_month (dt),
- g_date_time_get_hour (dt),
- g_date_time_get_minute (dt),
- g_date_time_get_second (dt),
- g_date_time_get_microsecond (dt) / 1000,
- str->str);
- g_date_time_unref (dt);
- } else {
- g_print ("[EDS-GOA] %s", str->str);
- }
-
- g_string_free (str, TRUE);
}
typedef struct _EGnomeOnlineAccounts EGnomeOnlineAccounts;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]