]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: suppress empty lines 3636/head
authorLennart Poettering <lennart@poettering.net>
Tue, 19 Jul 2016 12:27:05 +0000 (14:27 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 19 Jul 2016 15:51:20 +0000 (17:51 +0200)
Let's make sure our logging APIs is in sync with how stdout/stderr logging
works.

man/sd_journal_print.xml
src/journal/journal-send.c

index 6fe078d88e39c3fd2fa17549aa480de2ac202d8a..76542527fcd46e3bccf571bc93cf56bcc475d73f 100644 (file)
     but no such restrictions are enforced. Note that log messages written using this function are generally not
     expected to end in a new-line character. However, as all trailing whitespace (including spaces, new-lines,
     tabulators and carriage returns) are automatically stripped from the logged string, it is acceptable to specify one
-    (or more). Leading whitespace (as well as inner whitespace) is left unmodified however.</para>
+    (or more). Empty lines (after trailing whitespace removal) are suppressed. On non-empty lines, leading whitespace
+    (as well as inner whitespace) is left unmodified. </para>
 
     <para><function>sd_journal_printv()</function> is similar to
     <function>sd_journal_print()</function> but takes a variable
index 1b9258548864482781318480858c05366d088d8d..440fba67ca6cc98bb16dd8f973718feb5ffc851f 100644 (file)
@@ -110,6 +110,10 @@ _public_ int sd_journal_printv(int priority, const char *format, va_list ap) {
         /* Strip trailing whitespace, keep prefix whitespace. */
         (void) strstrip(buffer);
 
+        /* Suppress empty lines */
+        if (isempty(buffer+8))
+                return 0;
+
         zero(iov);
         IOVEC_SET_STRING(iov[0], buffer);
         IOVEC_SET_STRING(iov[1], p);
@@ -476,7 +480,12 @@ _public_ int sd_journal_printv_with_location(int priority, const char *file, con
         memcpy(buffer, "MESSAGE=", 8);
         vsnprintf(buffer+8, sizeof(buffer) - 8, format, ap);
 
-        (void) strstrip(buffer); /* strip trailing whitespace, keep prefixing whitespace */
+        /* Strip trailing whitespace, keep prefixing whitespace */
+        (void) strstrip(buffer);
+
+        /* Suppress empty lines */
+        if (isempty(buffer+8))
+                return 0;
 
         /* func is initialized from __func__ which is not a macro, but
          * a static const char[], hence cannot easily be prefixed with