diff --git a/src/evdev.h b/src/evdev.h index 65d599ce..e1851ff5 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -778,7 +778,7 @@ evdev_log_msg(struct evdev_device *device, va_list args; char buf[1024]; - if (!is_logged(evdev_libinput_context(device), priority)) + if (!log_is_logged(evdev_libinput_context(device), priority)) return; /* Anything info and above is user-visible, use the device name */ @@ -812,7 +812,7 @@ evdev_log_msg_ratelimit(struct evdev_device *device, enum ratelimit_state state; - if (!is_logged(evdev_libinput_context(device), priority)) + if (!log_is_logged(evdev_libinput_context(device), priority)) return; state = ratelimit_test(ratelimit); diff --git a/src/libinput-log.h b/src/libinput-log.h new file mode 100644 index 00000000..c7bb0f89 --- /dev/null +++ b/src/libinput-log.h @@ -0,0 +1,70 @@ +/* + * Copyright © 2013 Jonas Ådahl + * Copyright © 2013-2015 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include "config.h" + +#include + +#include "util-ratelimit.h" +#include "libinput.h" + +#define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) +#define log_info(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__) +#define log_error(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__) +#define log_bug_kernel(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__) +#define log_bug_libinput(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__) +#define log_bug_client(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__) + +#define log_debug_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) +#define log_info_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__) +#define log_error_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__) +#define log_bug_kernel_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__) +#define log_bug_libinput_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__) +#define log_bug_client_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__) + +bool +log_is_logged(const struct libinput *libinput, + enum libinput_log_priority priority); + +void +log_msg_ratelimit(struct libinput *libinput, + struct ratelimit *ratelimit, + enum libinput_log_priority priority, + const char *format, ...) + LIBINPUT_ATTRIBUTE_PRINTF(4, 5); + +void +log_msg(struct libinput *libinput, + enum libinput_log_priority priority, + const char *format, ...) + LIBINPUT_ATTRIBUTE_PRINTF(3, 4); + +void +log_msg_va(struct libinput *libinput, + enum libinput_log_priority priority, + const char *format, + va_list args) + LIBINPUT_ATTRIBUTE_PRINTF(3, 0); diff --git a/src/libinput-private.h b/src/libinput-private.h index 199eab4d..479c0bf6 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -38,6 +38,7 @@ #include "linux/input.h" #include "libinput.h" +#include "libinput-log.h" #include "libinput-private-config.h" #include "libinput-util.h" #include "libinput-version.h" @@ -594,48 +595,6 @@ struct libinput_event_listener { typedef void (*libinput_source_dispatch_t)(void *data); -#define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) -#define log_info(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__) -#define log_error(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__) -#define log_bug_kernel(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__) -#define log_bug_libinput(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__) -#define log_bug_client(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__) - -#define log_debug_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) -#define log_info_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__) -#define log_error_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__) -#define log_bug_kernel_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__) -#define log_bug_libinput_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__) -#define log_bug_client_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__) - -static inline bool -is_logged(const struct libinput *libinput, - enum libinput_log_priority priority) -{ - return libinput->log_handler && - libinput->log_priority <= priority; -} - -void -log_msg_ratelimit(struct libinput *libinput, - struct ratelimit *ratelimit, - enum libinput_log_priority priority, - const char *format, ...) - LIBINPUT_ATTRIBUTE_PRINTF(4, 5); - -void -log_msg(struct libinput *libinput, - enum libinput_log_priority priority, - const char *format, ...) - LIBINPUT_ATTRIBUTE_PRINTF(3, 4); - -void -log_msg_va(struct libinput *libinput, - enum libinput_log_priority priority, - const char *format, - va_list args) - LIBINPUT_ATTRIBUTE_PRINTF(3, 0); - int libinput_init(struct libinput *libinput, const struct libinput_interface *interface, diff --git a/src/libinput.c b/src/libinput.c index 5e331098..cda843db 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -282,13 +282,21 @@ libinput_default_log_func(struct libinput *libinput, vfprintf(stderr, format, args); } +bool +log_is_logged(const struct libinput *libinput, + enum libinput_log_priority priority) +{ + return libinput->log_handler && + libinput->log_priority <= priority; +} + void log_msg_va(struct libinput *libinput, enum libinput_log_priority priority, const char *format, va_list args) { - if (is_logged(libinput, priority)) + if (log_is_logged(libinput, priority)) libinput->log_handler(libinput, priority, format, args); }