From e991c05debb9a907ac5d17e17dba2b2c275632d3 Mon Sep 17 00:00:00 2001 From: rbuj Date: Thu, 12 Nov 2020 12:58:25 +0100 Subject: Remove the use of the gettimeofday function --- libcaja-private/caja-debug-log.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'libcaja-private') diff --git a/libcaja-private/caja-debug-log.c b/libcaja-private/caja-debug-log.c index 646e7f66..d872f91d 100644 --- a/libcaja-private/caja-debug-log.c +++ b/libcaja-private/caja-debug-log.c @@ -25,11 +25,14 @@ #include #include #include -#include -#include #include "caja-debug-log.h" #include "caja-file.h" +#if !GLIB_CHECK_VERSION(2,65,2) +#include +#include +#endif + #define DEFAULT_RING_BUFFER_NUM_LINES 1000 #define KEY_FILE_GROUP "debug log" @@ -151,8 +154,13 @@ caja_debug_logv (gboolean is_milestone, const char *domain, const GList *uris, c { char *str; char *debug_str; +#if GLIB_CHECK_VERSION(2,65,2) + char *date_str; + GDateTime* datetime; +#else struct timeval tv; struct tm tm; +#endif lock (); @@ -160,10 +168,20 @@ caja_debug_logv (gboolean is_milestone, const char *domain, const GList *uris, c goto out; str = g_strdup_vprintf (format, args); - gettimeofday (&tv, NULL); +#if GLIB_CHECK_VERSION(2,65,2) + datetime = g_date_time_new_now_local (); + date_str = g_date_time_format (datetime, "%Y/%m/%d %H:%M:%S.%f"); + g_date_time_unref (datetime); + debug_str = g_strdup_printf ("%p %s (%s): %s", + g_thread_self (), + date_str, + domain, + str); + g_free (date_str); +#else + gettimeofday (&tv, NULL); tm = *localtime (&tv.tv_sec); - debug_str = g_strdup_printf ("%p %04d/%02d/%02d %02d:%02d:%02d.%04d (%s): %s", g_thread_self (), tm.tm_year + 1900, @@ -175,6 +193,7 @@ caja_debug_logv (gboolean is_milestone, const char *domain, const GList *uris, c (int) (tv.tv_usec / 100), domain, str); +#endif g_free (str); if (uris) -- cgit v1.2.1