[Pkg-gnupg-commit] [gnupg2] 164/205: common: Extend log_string to indent lines.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed May 11 08:38:34 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch experimental
in repository gnupg2.

commit 35f4b6aafdf1889ed1ae569af5852f47738fe993
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Apr 29 21:45:15 2016 +0200

    common: Extend log_string to indent lines.
    
    * common/logging.c (do_logv): Add indentation when called via
    log_string.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 common/logging.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/common/logging.c b/common/logging.c
index 7c54d72..9175b4f 100644
--- a/common/logging.c
+++ b/common/logging.c
@@ -715,7 +715,21 @@ do_logv (int level, int ignore_arg_ptr, const char *fmt, va_list arg_ptr)
   if (fmt)
     {
       if (ignore_arg_ptr)
-        es_fputs_unlocked (fmt, logstream);
+        { /* This is used by log_string and comes with the extra
+           * feature that after a LF the next line is indent at the
+           * length of the prefix.  Note that we do not yet include
+           * the length of the timestamp and pid in the indent
+           * computation.  */
+          const char *p, *pend;
+
+          for (p = fmt; (pend = strchr (p, '\n')); p = pend+1)
+            es_fprintf_unlocked (logstream, "%*s%.*s",
+                                 (int)((p != fmt
+                                        && (with_prefix || force_prefixes))
+                                       ?strlen (prefix_buffer)+2:0), "",
+                                 (int)(pend - p)+1, p);
+          es_fputs_unlocked (p, logstream);
+        }
       else
         es_vfprintf_unlocked (logstream, fmt, arg_ptr);
       if (*fmt && fmt[strlen(fmt)-1] != '\n')
@@ -769,12 +783,13 @@ do_log_ignore_arg (int level, const char *str, ...)
 }
 
 
+/* Log STRING at LEVEL but indent from the second line on by the
+ * length of the prefix.  */
 void
 log_string (int level, const char *string)
 {
   /* We need a dummy arg_ptr, but there is no portable way to create
-     one.  So we call the do_logv function through a variadic wrapper.
-     MB: Why not just use "%s"?  */
+   * one.  So we call the do_logv function through a variadic wrapper. */
   do_log_ignore_arg (level, string);
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list