util/log: Don't print an extra \n if the format string had one.
authorEmma Anholt <emma@anholt.net>
Thu, 10 Mar 2022 20:30:16 +0000 (12:30 -0800)
committerMarge Bot <emma+marge@anholt.net>
Tue, 5 Apr 2022 21:37:46 +0000 (21:37 +0000)
You're not supposed to include a '\n' in mesa_log*() messages because
android logging will log what you provide on its own line anyway, so each
mesa_log() should be the body of a log line.  But also, getting everyone
to consistently not do that is hopeless because we're all so trained by
printf().  So, just detect an existing \n and don't add a new one.

Cleans up deqp-vk debug output a bunch from turnip.

Acked-by: Daniel Stone <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15332>

src/util/log.c

index e0f2a90..140485f 100644 (file)
@@ -87,7 +87,8 @@ mesa_log_v(enum mesa_log_level level, const char *tag, const char *format,
 #endif
    fprintf(stderr, "%s: %s: ", tag, level_to_str(level));
    vfprintf(stderr, format, va);
-   fprintf(stderr, "\n");
+   if (format[strlen(format) - 1] != '\n')
+      fprintf(stderr, "\n");
 #if !DETECT_OS_WINDOWS
    funlockfile(stderr);
 #endif