mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-20 23:10:06 +01:00
Log to stderr by default
The logging we do use atm inside the library is largely to spot application errors. Log that to stderr by default so it doesn't get lost. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
parent
4b5ffa6bea
commit
ad709cf953
2 changed files with 29 additions and 5 deletions
|
|
@ -49,11 +49,32 @@ init_event_queue(struct libevdev *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
libevdev_noop_log_func(enum libevdev_log_priority priority,
|
libevdev_dflt_log_func(enum libevdev_log_priority priority,
|
||||||
void *data,
|
void *data,
|
||||||
const char *file, int line, const char *func,
|
const char *file, int line, const char *func,
|
||||||
const char *format, va_list args)
|
const char *format, va_list args)
|
||||||
{
|
{
|
||||||
|
const char *prefix;
|
||||||
|
switch(priority) {
|
||||||
|
case LIBEVDEV_LOG_ERROR: prefix = "libevdev error"; break;
|
||||||
|
case LIBEVDEV_LOG_INFO: prefix = "libevdev info"; break;
|
||||||
|
case LIBEVDEV_LOG_DEBUG:
|
||||||
|
prefix = "libevdev debug";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* default logging format:
|
||||||
|
libevev error in libevdev_some_func: blah blah
|
||||||
|
libevev info in libevdev_some_func: blah blah
|
||||||
|
libevev debug in file.c:123:libevdev_some_func: blah blah
|
||||||
|
*/
|
||||||
|
|
||||||
|
fprintf(stderr, "%s in ", prefix);
|
||||||
|
if (priority == LIBEVDEV_LOG_DEBUG)
|
||||||
|
fprintf(stderr, "%s:%d:", file, line);
|
||||||
|
fprintf(stderr, "%s: ", func);
|
||||||
|
vfprintf(stderr, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -61,7 +82,7 @@ libevdev_noop_log_func(enum libevdev_log_priority priority,
|
||||||
*/
|
*/
|
||||||
struct logdata log_data = {
|
struct logdata log_data = {
|
||||||
LIBEVDEV_LOG_INFO,
|
LIBEVDEV_LOG_INFO,
|
||||||
libevdev_noop_log_func,
|
libevdev_dflt_log_func,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -73,6 +94,9 @@ log_msg(enum libevdev_log_priority priority,
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
|
if (!log_data.handler)
|
||||||
|
return;
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
log_data.handler(priority, data, file, line, func, format, args);
|
log_data.handler(priority, data, file, line, func, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
@ -137,7 +161,7 @@ libevdev_set_log_handler(struct libevdev *dev, libevdev_log_func_t logfunc)
|
||||||
LIBEVDEV_EXPORT void
|
LIBEVDEV_EXPORT void
|
||||||
libevdev_set_log_function(libevdev_log_func_t logfunc, void *data)
|
libevdev_set_log_function(libevdev_log_func_t logfunc, void *data)
|
||||||
{
|
{
|
||||||
log_data.handler = logfunc ? logfunc : libevdev_noop_log_func;
|
log_data.handler = logfunc;
|
||||||
log_data.userdata = data;
|
log_data.userdata = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -377,10 +377,10 @@ typedef void (*libevdev_log_func_t)(enum libevdev_log_priority priority,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a printf-style logging handler for library-internal logging. The default
|
* Set a printf-style logging handler for library-internal logging. The default
|
||||||
* logging function is a noop.
|
* logging function is to stdout.
|
||||||
*
|
*
|
||||||
* @param logfunc The logging function for this device. If NULL, the current
|
* @param logfunc The logging function for this device. If NULL, the current
|
||||||
* logging function is unset.
|
* logging function is unset and no logging is performed.
|
||||||
* @param data User-specific data passed to the log handler.
|
* @param data User-specific data passed to the log handler.
|
||||||
*
|
*
|
||||||
* @note This function may be called before libevdev_set_fd().
|
* @note This function may be called before libevdev_set_fd().
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue