diff options
author | Thomas Haller <thaller@redhat.com> | 2021-07-21 13:19:50 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-07-21 14:31:29 +0200 |
commit | cc1931ccbfabd6eb7e67617f52095811253a84e6 (patch) | |
tree | 689feb25c0b443469bfae5efa470cbf44d414b70 | |
parent | acc5a54cc21821a7f467033716038b1a164bc83c (diff) | |
download | NetworkManager-th/cloud-setup-logging.tar.gz |
glib-aux: use nm_vsprintf_buf_or_alloc() to stack allocate logging message in _nm_log_simple_printf()th/cloud-setup-logging
Also take the timestamp first.
-rw-r--r-- | src/libnm-glib-aux/nm-logging-base.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/libnm-glib-aux/nm-logging-base.c b/src/libnm-glib-aux/nm-logging-base.c index b195440af9..cc19ef15db 100644 --- a/src/libnm-glib-aux/nm-logging-base.c +++ b/src/libnm-glib-aux/nm-logging-base.c @@ -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, |