Auto-append newline

This commit is contained in:
Johannes Marbach 2021-09-25 14:34:54 +02:00
parent 40ad7e89c2
commit 1ebc98476d
3 changed files with 11 additions and 5 deletions

View file

@ -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;

8
log.c
View file

@ -21,6 +21,7 @@
#include "log.h"
#include <stdarg.h>
#include <string.h>
/**
@ -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);
}

2
log.h
View file

@ -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