Debug: avoid indenting line-prefixes (timestamp, pid, host-checking marker)
[exim.git] / src / src / debug.c
index 8f9359b15837b9702a9e6616d3cd583bdd21e6d5..ee284d0be7540d23953bdde94116dc04c3c5a803 100644 (file)
@@ -137,7 +137,7 @@ debug_printf("%s uid=%ld gid=%ld euid=%ld egid=%ld\n", s,
 *************************************************/
 
 /* There are two entries, one for use when being called directly from a
-function with a variable argument list.
+function with a variable argument list, one for prepending an indent.
 
 If debug_pid is nonzero, print the pid at the start of each line. This is for
 tidier output when running parallel remote deliveries with debugging turned on.
@@ -146,17 +146,28 @@ get interleaved. Since some calls to debug_printf() don't end with newline,
 we save up the text until we do get the newline.
 Take care to not disturb errno. */
 
+
+/* Debug printf indented by ACL nest depth */
+void
+debug_printf_indent(const char * format, ...)
+{
+va_list ap;
+va_start(ap, format);
+debug_vprintf(acl_level + expand_level, format, ap);
+va_end(ap);
+}
+
 void
 debug_printf(const char *format, ...)
 {
 va_list ap;
 va_start(ap, format);
-debug_vprintf(format, ap);
+debug_vprintf(0, format, ap);
 va_end(ap);
 }
 
 void
-debug_vprintf(const char *format, va_list ap)
+debug_vprintf(int indent, const char *format, va_list ap)
 {
 int save_errno = errno;
 
@@ -195,6 +206,18 @@ if (debug_ptr == debug_buffer)
   debug_prefix_length = debug_ptr - debug_buffer;
   }
 
+if (indent > 0)
+  {
+  int i;
+  for (i = indent >> 2; i > 0; i--)
+    {
+    Ustrcpy(debug_ptr, "   .");
+    debug_ptr += 4;
+    }
+  Ustrncpy(debug_ptr, "   ", indent & 3);
+  debug_ptr += indent & 3;
+  }
+
 /* Use the checked formatting routine to ensure that the buffer
 does not overflow. Ensure there's space for a newline at the end. */