From 1ebc98476dd379e5c0b2d59e5bf158f2597022c1 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Sat, 25 Sep 2021 14:34:54 +0200 Subject: [PATCH] Auto-append newline --- indev.c | 6 +++--- log.c | 8 +++++++- log.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/indev.c b/indev.c index b1cb4a6..27690bb 100644 --- a/indev.c +++ b/indev.c @@ -132,13 +132,13 @@ static void auto_connect(libinput_capability capability, int max_num_devs, int * static void log_connection(libinput_capability capability, char *dev) { switch (capability) { case LIBINPUT_CAPABILITY_KEYBOARD: - ul_log(UL_LOG_LEVEL_VERBOSE, "Connecting keyboard device %s\n", dev); + ul_log(UL_LOG_LEVEL_VERBOSE, "Connecting keyboard device %s", dev); break; case LIBINPUT_CAPABILITY_POINTER: - ul_log(UL_LOG_LEVEL_VERBOSE, "Connecting pointer device %s\n", dev); + ul_log(UL_LOG_LEVEL_VERBOSE, "Connecting pointer device %s", dev); break; case LIBINPUT_CAPABILITY_TOUCH: - ul_log(UL_LOG_LEVEL_VERBOSE, "Connecting touchscreen device %s\n", dev); + ul_log(UL_LOG_LEVEL_VERBOSE, "Connecting touchscreen device %s", dev); break; case LIBINPUT_CAPABILITY_NONE: break; diff --git a/log.c b/log.c index c0c4f34..fe874c0 100644 --- a/log.c +++ b/log.c @@ -21,6 +21,7 @@ #include "log.h" #include +#include /** @@ -47,8 +48,13 @@ void ul_log(ul_log_level level, const char *format, ...) { va_start(args, format); vfprintf(stderr, format, args); va_end(args); + + size_t l = strlen(format); + if (l > 0 && format[l - 1] != '\n') { + fprintf(stderr, "\n"); + } } void ul_log_print_cb(const char *msg) { - ul_log(UL_LOG_LEVEL_VERBOSE, "%s\n", msg); + ul_log(UL_LOG_LEVEL_VERBOSE, msg); } diff --git a/log.h b/log.h index 9cbec01..4f2c415 100644 --- a/log.h +++ b/log.h @@ -41,7 +41,7 @@ typedef enum { void ul_log_set_level(ul_log_level level); /** - * Log a message. + * Log a message. A newline character is appended unless the message ends in one. * * @param level log level of the message * @param format message format string