Debugging: millisecond timestamps. Bug 2102
[exim.git] / src / src / debug.c
index ee284d0be7540d23953bdde94116dc04c3c5a803..f6c8b2f62eb7cd61480da828512aa2cb97f44895 100644 (file)
@@ -182,17 +182,21 @@ if (debug_ptr == debug_buffer)
   {
   DEBUG(D_timestamp)
     {
-    time_t now = time(NULL);
-    struct tm *t = timestamps_utc? gmtime(&now) : localtime(&now);
-    (void) sprintf(CS debug_ptr, "%02d:%02d:%02d ", t->tm_hour, t->tm_min,
-      t->tm_sec);
-    while(*debug_ptr != 0) debug_ptr++;
+    struct timeval now;
+    time_t tmp;
+    struct tm * t;
+
+    gettimeofday(&now, NULL);
+    tmp = now.tv_sec;
+    t = timestamps_utc ? gmtime(&now) : localtime(&now);
+    debug_ptr += sprintf(CS debug_ptr,
+      LOGGING(millisec) ? "%02d:%02d:%02d.%03d " : "%02d:%02d:%02d ",
+      t->tm_hour, t->tm_min, t->tm_sec, now.tv_usec/1000);
     }
 
   DEBUG(D_pid)
     {
-    sprintf(CS debug_ptr, "%5d ", (int)getpid());
-    while(*debug_ptr != 0) debug_ptr++;
+    debug_ptr += sprintf(CS debug_ptr, "%5d ", (int)getpid());
     }
 
   /* Set up prefix if outputting for host checking and not debugging */
@@ -211,11 +215,13 @@ if (indent > 0)
   int i;
   for (i = indent >> 2; i > 0; i--)
     {
-    Ustrcpy(debug_ptr, "   .");
-    debug_ptr += 4;
+    Ustrcpy(debug_ptr, "   " UTF8_VERT_2DASH);
+    debug_ptr += 6;    /* 3 spaces + 3 UTF-8 octets */
+    debug_prefix_length += 6;
     }
-  Ustrncpy(debug_ptr, "   ", indent & 3);
-  debug_ptr += indent & 3;
+  Ustrncpy(debug_ptr, "   ", indent &= 3);
+  debug_ptr += indent;
+  debug_prefix_length += indent;
   }
 
 /* Use the checked formatting routine to ensure that the buffer