Add microseconds to timestamp in debug log messages
This commit is contained in:
parent
3608d6717b
commit
09706bdf8b
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
19
src/utils.c
19
src/utils.c
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user