vlog: Trim trailing new-lines from log messages.
authorBen Pfaff <blp@nicira.com>
Wed, 18 Mar 2009 23:27:02 +0000 (16:27 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 18 Mar 2009 23:39:23 +0000 (16:39 -0700)
Sometimes a message passed into a vlog function will have a trailing
new-line due to carelessness.  Tolerate this situation by just
trimming them off in format_log_message().

lib/vlog.c

index 08f1e4ebc51aae3bce9ff998a89ee75f622e46c7..fc5f9a106e66c9732f8f9ffacc20eff8d56f6e82 100644 (file)
@@ -522,9 +522,14 @@ format_log_message(enum vlog_module module, enum vlog_level level,
             ds_put_strftime(s, tmp, NULL);
             break;
         case 'm':
+            /* Format user-supplied log message and trim trailing new-lines. */
+            length = s->length;
             va_copy(args, args_);
             ds_put_format_valist(s, message, args);
             va_end(args);
+            while (s->length > length && s->string[s->length - 1] == '\n') {
+                s->length--;
+            }
             break;
         case 'N':
             ds_put_format(s, "%u", msg_num);