[geany/geany] 09706b: Add microseconds to timestamp in debug log messages

Enrico Tröger git-noreply at xxxxx
Sun Sep 12 11:31:53 UTC 2021


Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Sun, 12 Sep 2021 11:31:53 UTC
Commit:      09706bdf8bd61f740a053aa1ea709fc4f65845c5
             https://github.com/geany/geany/commit/09706bdf8bd61f740a053aa1ea709fc4f65845c5

Log Message:
-----------
Add microseconds to timestamp in debug log messages


Modified Paths:
--------------
    src/log.c
    src/msgwindow.c
    src/utils.c
    src/utils.h

Modified: src/log.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -137,7 +137,7 @@ static void handler_log(const gchar *domain, GLogLevelFlags level, const gchar *
 #endif
 	}
 
-	time_str = utils_get_current_time_string();
+	time_str = utils_get_current_time_string(TRUE);
 
 	g_string_append_printf(log_buffer, "%s: %s %s: %s\n", time_str, domain,
 		get_log_prefix(level), msg);


Modified: src/msgwindow.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -484,7 +484,7 @@ void msgwin_status_add_string(const gchar *string)
 	gchar *statusmsg, *time_str;
 
 	/* add a timestamp to status messages */
-	time_str = utils_get_current_time_string();
+	time_str = utils_get_current_time_string(FALSE);
 	statusmsg = g_strconcat(time_str, ": ", string, NULL);
 	g_free(time_str);
 


Modified: src/utils.c
19 lines changed, 10 insertions(+), 9 deletions(-)
===================================================================
@@ -1012,16 +1012,17 @@ gint utils_parse_color_to_bgr(const gchar *spec)
 }
 
 
-/* Returns: newly allocated string with the current time formatted HH:MM:SS. */
-gchar *utils_get_current_time_string(void)
+/* Returns: newly allocated string with the current time formatted HH:MM:SS.
+ * If "include_microseconds" is TRUE, microseconds are appended.
+ *
+ * The returned string should be freed with g_free(). */
+gchar *utils_get_current_time_string(gboolean include_microseconds)
 {
-	const time_t tp = time(NULL);
-	const struct tm *tmval = localtime(&tp);
-	gchar *result = g_malloc0(9);
-
-	strftime(result, 9, "%H:%M:%S", tmval);
-	result[8] = '\0';
-	return result;
+	GDateTime *now = g_date_time_new_now_local();
+	const gchar *format = include_microseconds ? "%H:%M:%S.%f" : "%H:%M:%S";
+	gchar *time_string = g_date_time_format(now, format);
+	g_date_time_unref(now);
+	return time_string;
 }
 
 


Modified: src/utils.h
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -287,7 +287,7 @@ gint utils_color_to_bgr(const GdkColor *color);
 
 gint utils_parse_color_to_bgr(const gchar *spec);
 
-gchar *utils_get_current_time_string(void);
+gchar *utils_get_current_time_string(gboolean include_microseconds);
 
 GIOChannel *utils_set_up_io_channel(gint fd, GIOCondition cond, gboolean nblock,
 									GIOFunc func, gpointer data);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list