Blame SOURCES/0022-DEBUG-changed-timestamp-output-format.patch

836b22
From 502138b2281a7fab3391c0f46d807ba285307a03 Mon Sep 17 00:00:00 2001
836b22
From: Alexey Tikhonov <atikhono@redhat.com>
836b22
Date: Mon, 4 May 2020 16:54:13 +0200
836b22
Subject: [PATCH 22/25] DEBUG: changed timestamp output format
836b22
MIME-Version: 1.0
836b22
Content-Type: text/plain; charset=UTF-8
836b22
Content-Transfer-Encoding: 8bit
836b22
836b22
Changed timestamp format from (example) "(Tue Apr 21 14:35:30 2020)" to
836b22
"(2020-04-21 14:35:30)" to have tidier and "sorting friendly" logs.
836b22
836b22
Reviewed-by: Pawel Polawski <ppolawsk@redhat.com>
836b22
(cherry picked from commit 7b25375155e7b7f640d30dcfdf5b55482a6102a7)
836b22
836b22
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
836b22
836b22
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
836b22
---
836b22
 src/tests/debug-tests.c | 32 ++++++++++++++++----------------
836b22
 src/util/debug.c        | 24 +++++++-----------------
836b22
 2 files changed, 23 insertions(+), 33 deletions(-)
836b22
836b22
diff --git a/src/tests/debug-tests.c b/src/tests/debug-tests.c
836b22
index 1446ec047..95b0a8f00 100644
836b22
--- a/src/tests/debug-tests.c
836b22
+++ b/src/tests/debug-tests.c
836b22
@@ -190,29 +190,29 @@ int test_helper_debug_check_message(int level)
836b22
     msg[fsize] = '\0';
836b22
 
836b22
     if (debug_timestamps == 1) {
836b22
-        char time_day[4] = {'\0', '\0', '\0', '\0'};
836b22
-        char time_month[4] = {'\0', '\0', '\0', '\0'};
836b22
-        int time_day_num = 0;
836b22
         int time_hour = 0;
836b22
         int time_min = 0;
836b22
         int time_sec = 0;
836b22
         int time_usec = 0;
836b22
+        int time_day = 0;
836b22
+        int time_month = 0;
836b22
         int time_year = 0;
836b22
         int scan_return = 0;
836b22
 
836b22
         if (debug_microseconds == 0) {
836b22
-            scan_return = sscanf(msg, "(%s %s %d %d:%d:%d %d)", time_day, time_month,
836b22
-                                 &time_day_num, &time_hour, &time_min, &time_sec, &time_year);
836b22
+            scan_return = sscanf(msg, "(%d-%d-%d %d:%d:%d)", &time_year,
836b22
+                                 &time_month, &time_day, &time_hour,
836b22
+                                 &time_min, &time_sec);
836b22
 
836b22
-            if (scan_return != 7) {
836b22
+            if (scan_return != 6) {
836b22
                 ret = DEBUG_TEST_NOK_TS;
836b22
                 goto done;
836b22
             }
836b22
             compare_to = talloc_asprintf(ctx,
836b22
-                                         "(%s %s %2d %.2d:%.2d:%.2d %.4d) "
836b22
+                                         "(%d-%02d-%02d %2d:%02d:%02d): "
836b22
                                          "[%s] [%s] (%#.4x): %s\n",
836b22
-                                         time_day, time_month, time_day_num,
836b22
-                                         time_hour, time_min, time_sec, time_year,
836b22
+                                         time_year, time_month, time_day,
836b22
+                                         time_hour, time_min, time_sec,
836b22
                                          debug_prg_name, function, level, body);
836b22
             if (compare_to == NULL) {
836b22
                 _errno = ENOMEM;
836b22
@@ -220,20 +220,20 @@ int test_helper_debug_check_message(int level)
836b22
                 goto done;
836b22
             }
836b22
         } else {
836b22
-            scan_return = sscanf(msg, "(%s %s %d %d:%d:%d:%d %d)", time_day, time_month,
836b22
-                                 &time_day_num, &time_hour, &time_min, &time_sec,
836b22
-                                 &time_usec, &time_year);
836b22
+            scan_return = sscanf(msg, "(%d-%d-%d %d:%d:%d:%d)", &time_year,
836b22
+                                 &time_month, &time_day, &time_hour,
836b22
+                                 &time_min, &time_sec, &time_usec);
836b22
 
836b22
-            if (scan_return != 8) {
836b22
+            if (scan_return != 7) {
836b22
                 ret = DEBUG_TEST_NOK_TS;
836b22
                 goto done;
836b22
             }
836b22
             compare_to = talloc_asprintf(ctx,
836b22
-                                         "(%s %s %2d %.2d:%.2d:%.2d:%.6d %.4d) "
836b22
+                                         "(%d-%02d-%02d %2d:%02d:%02d:%.6d): "
836b22
                                          "[%s] [%s] (%#.4x): %s\n",
836b22
-                                         time_day, time_month, time_day_num,
836b22
+                                         time_year, time_month, time_day,
836b22
                                          time_hour, time_min, time_sec, time_usec,
836b22
-                                         time_year, debug_prg_name, function, level, body);
836b22
+                                         debug_prg_name, function, level, body);
836b22
             if (compare_to == NULL) {
836b22
                 _errno = ENOMEM;
836b22
                 ret = DEBUG_TEST_ERROR;
836b22
diff --git a/src/util/debug.c b/src/util/debug.c
836b22
index 30801fce7..0c8e42ad0 100644
836b22
--- a/src/util/debug.c
836b22
+++ b/src/util/debug.c
836b22
@@ -270,8 +270,6 @@ void sss_vdebug_fn(const char *file,
836b22
 {
836b22
     struct timeval tv;
836b22
     struct tm *tm;
836b22
-    char datetime[20];
836b22
-    int year;
836b22
 
836b22
 #ifdef WITH_JOURNALD
836b22
     errno_t ret;
836b22
@@ -300,25 +298,17 @@ void sss_vdebug_fn(const char *file,
836b22
     if (debug_timestamps) {
836b22
         gettimeofday(&tv, NULL);
836b22
         tm = localtime(&tv.tv_sec);
836b22
-        year = tm->tm_year + 1900;
836b22
-        /* get date time without year */
836b22
-        memcpy(datetime, ctime(&tv.tv_sec), 19);
836b22
-        datetime[19] = '\0';
836b22
+        debug_printf("(%d-%02d-%02d %2d:%02d:%02d",
836b22
+                     tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
836b22
+                     tm->tm_hour, tm->tm_min, tm->tm_sec);
836b22
         if (debug_microseconds) {
836b22
-            debug_printf("(%s:%.6ld %d) [%s] [%s] (%#.4x): ",
836b22
-                         datetime, tv.tv_usec,
836b22
-                         year, debug_prg_name,
836b22
-                         function, level);
836b22
-        } else {
836b22
-            debug_printf("(%s %d) [%s] [%s] (%#.4x): ",
836b22
-                         datetime, year,
836b22
-                         debug_prg_name, function, level);
836b22
+            debug_printf(":%.6ld", tv.tv_usec);
836b22
         }
836b22
-    } else {
836b22
-        debug_printf("[%s] [%s] (%#.4x): ",
836b22
-                     debug_prg_name, function, level);
836b22
+        debug_printf("): ");
836b22
     }
836b22
 
836b22
+    debug_printf("[%s] [%s] (%#.4x): ", debug_prg_name, function, level);
836b22
+
836b22
     debug_vprintf(format, ap);
836b22
     if (flags & APPEND_LINE_FEED) {
836b22
         debug_printf("\n");
836b22
-- 
836b22
2.21.1
836b22