summary refs log tree commit diff
path: root/src/libnm-log-core
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2023-08-09 21:55:35 +0200
committerMichael Biebl <biebl@debian.org>2023-08-09 21:55:35 +0200
commit05e4a733f2141995181a551854d5df929f084adf (patch)
tree83bb937740a6667525ba0df046748ecaa829c269 /src/libnm-log-core
parent14b0f3a9dc9ea90d60a3b057350fd4d637dc021a (diff)
New upstream version 1.44.0 upstream/1.44.0
Diffstat (limited to 'src/libnm-log-core')
-rw-r--r--src/libnm-log-core/nm-logging.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/libnm-log-core/nm-logging.c b/src/libnm-log-core/nm-logging.c
index 5cce508d..0909e799 100644
--- a/src/libnm-log-core/nm-logging.c
+++ b/src/libnm-log-core/nm-logging.c
@@ -665,7 +665,7 @@ _nm_log_impl(const char *file,
     char               msg_stack[400];
     gs_free char      *msg_heap = NULL;
     const char        *msg;
-    GTimeVal           tv;
+    gint64             tv;
     int                errsv;
     const NMLogDomain *cur_log_state;
     NMLogDomain        cur_log_state_copy[_LOGL_N_REAL];
@@ -707,11 +707,26 @@ _nm_log_impl(const char *file,
 
     msg = nm_vsprintf_buf_or_alloc(fmt, fmt, msg_stack, &msg_heap, NULL);
 
-#define MESSAGE_FMT "%s%-7s [%ld.%04ld] %s"
-#define MESSAGE_ARG(prefix, tv, msg) \
-    prefix, nm_log_level_desc[level].level_str, (tv).tv_sec, ((tv).tv_usec / 100), (msg)
-
-    g_get_current_time(&tv);
+    /* We always print the level and the timestamp.
+     *
+     * Timestamps are very useful for understanding logfiles. While journalctl
+     * might record the timestamp, it is not present in plain `journalctl` output.
+     * Users who report a bug would simply send us the `journalctl` output and
+     * requesting an output with timestamps (even if it's stored somewhere inside
+     * journald) is not workable.
+     *
+     * We print the level, because this too, it's to quickly identify the severity
+     * of a message.
+     *
+     * We also do this for all messages (for all levels), because then the logging
+     * lines are formatted and aligned in a consistent way, which aids reading the
+     * logs. */
+#define MESSAGE_FMT "%s%-7s [%" G_GINT64_FORMAT ".%04d] %s"
+#define MESSAGE_ARG(prefix, tv, msg)                                            \
+    prefix, nm_log_level_desc[level].level_str, ((tv) / NM_UTILS_USEC_PER_SEC), \
+        ((int) ((((tv) % NM_UTILS_USEC_PER_SEC)) / ((gint64) 100))), (msg)
+
+    tv = g_get_real_time();
 
     if (g->debug_stderr)
         g_printerr(MESSAGE_FMT "\n", MESSAGE_ARG(g->prefix, tv, msg));