summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2011-01-10 14:00:49 +0000
committerJonny Lamb <jonny.lamb@collabora.co.uk>2011-01-10 14:00:49 +0000
commit3d447f257f072e519be06d2104eee8d80c2d22c5 (patch)
treea32ccd6378bdd409776ba89b5bca0b569b281d39
parentfe8dd650a78d535693aabdd5af7116955f65d431 (diff)
debug-sender: add tp_debug_sender_set_timestampsqed
Fixes: fd.o#26516 Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--docs/reference/telepathy-glib-sections.txt1
-rw-r--r--telepathy-glib/debug-sender.c48
-rw-r--r--telepathy-glib/debug-sender.h2
3 files changed, 50 insertions, 1 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index aa83aebd8..21844af76 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -4612,6 +4612,7 @@ TpDebugSender
tp_debug_sender_dup
tp_debug_sender_add_message
tp_debug_sender_log_handler
+tp_debug_sender_set_timestamps
<SUBSECTION Standard>
tp_debug_sender_get_type
TP_DEBUG_SENDER
diff --git a/telepathy-glib/debug-sender.c b/telepathy-glib/debug-sender.c
index 6acd0152b..7c8a490e2 100644
--- a/telepathy-glib/debug-sender.c
+++ b/telepathy-glib/debug-sender.c
@@ -78,6 +78,7 @@ static void debug_iface_init (gpointer g_iface, gpointer iface_data);
struct _TpDebugSenderPrivate
{
gboolean enabled;
+ gboolean timestamps;
GQueue *messages;
};
@@ -456,6 +457,10 @@ tp_debug_sender_idle (gpointer data)
* It can easily be re-implemented in services, and does not need to be
* used.
*
+ * If timestamps should be prepended to messages (like in
+ * tp_debug_timestamped_log_handler()), tp_debug_sender_set_messages()
+ * should also be called.
+ *
* Since version 0.11.15, this function can be called from any thread.
*
* Since: 0.7.36
@@ -466,7 +471,25 @@ tp_debug_sender_log_handler (const gchar *log_domain,
const gchar *message,
gpointer exclude)
{
- g_log_default_handler (log_domain, log_level, message, NULL);
+ if (debug_sender != NULL && ((TpDebugSender *) debug_sender)->priv->timestamps)
+ {
+ GTimeVal now;
+ gchar *now_str, *tmp;
+
+ g_get_current_time (&now);
+ now_str = g_time_val_to_iso8601 (&now);
+
+ tmp = g_strdup_printf ("%s: %s", now_str, message);
+
+ g_log_default_handler (log_domain, log_level, tmp, NULL);
+
+ g_free (now_str);
+ g_free (tmp);
+ }
+ else
+ {
+ g_log_default_handler (log_domain, log_level, message, NULL);
+ }
if (exclude == NULL || tp_strdiff (log_domain, exclude))
{
@@ -478,3 +501,26 @@ tp_debug_sender_log_handler (const gchar *log_domain,
NULL);
}
}
+
+/**
+ * tp_debug_sender_set_timestamps:
+ * @self: a #TpDebugSender
+ * @maybe: whether to display message timestamps
+ *
+ * If the log handler is tp_debug_sender_log_handler() then calling
+ * this function with %TRUE on the debug sender will prepend the
+ * message to be printed to stdout with the UTC time (currently in ISO
+ * 8601 format, with microsecond resolution). This is equivalent to
+ * using tp_debug_timestamped_log_handler() as the log handler, but
+ * also logging to the debug sender.
+ *
+ * Since: 0.13.UNRELEASED
+ */
+void
+tp_debug_sender_set_timestamps (TpDebugSender *self,
+ gboolean maybe)
+{
+ g_return_if_fail (TP_IS_DEBUG_SENDER (self));
+
+ self->priv->timestamps = maybe;
+}
diff --git a/telepathy-glib/debug-sender.h b/telepathy-glib/debug-sender.h
index 292e8e88d..5b1f73c2a 100644
--- a/telepathy-glib/debug-sender.h
+++ b/telepathy-glib/debug-sender.h
@@ -72,6 +72,8 @@ void tp_debug_sender_add_message (TpDebugSender *self,
void tp_debug_sender_log_handler (const gchar *log_domain,
GLogLevelFlags log_level, const gchar *message, gpointer exclude);
+void tp_debug_sender_set_timestamps (TpDebugSender *self, gboolean maybe);
+
G_END_DECLS
#endif /* __TP_DEBUG_SENDER_H__ */