glib-aux: use nm_vsprintf_buf_or_alloc() to stack allocate logging message in _nm_log_simple_printf()

Also take the timestamp first.
This commit is contained in:
Thomas Haller 2021-07-21 13:19:50 +02:00
parent 6c030ed923
commit 443f348776
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -102,14 +102,15 @@ _nm_logging_enabled_init(const char *level_str)
void
_nm_log_simple_printf(NMLogLevel level, const char *fmt, ...)
{
gs_free char *msg = NULL;
va_list ap;
gs_free char *msg_heap = NULL;
char msg_stack[700];
const char * msg;
const char * level_str;
gint64 ts;
va_start(ap, fmt);
msg = g_strdup_vprintf(fmt, ap);
va_end(ap);
ts = nm_utils_clock_gettime_nsec(CLOCK_BOOTTIME);
msg = nm_vsprintf_buf_or_alloc(fmt, fmt, msg_stack, &msg_heap, NULL);
switch (level) {
case LOGL_TRACE:
@ -130,8 +131,6 @@ _nm_log_simple_printf(NMLogLevel level, const char *fmt, ...)
break;
}
ts = nm_utils_clock_gettime_nsec(CLOCK_BOOTTIME);
g_print("[%" G_GINT64_FORMAT ".%05" G_GINT64_FORMAT "] %s %s\n",
ts / NM_UTILS_NSEC_PER_SEC,
(ts / (NM_UTILS_NSEC_PER_SEC / 10000)) % 10000,