}
static void
-libevdev_noop_log_func(enum libevdev_log_priority priority,
+libevdev_dflt_log_func(enum libevdev_log_priority priority,
void *data,
const char *file, int line, const char *func,
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);
}
/*
*/
struct logdata log_data = {
LIBEVDEV_LOG_INFO,
- libevdev_noop_log_func,
+ libevdev_dflt_log_func,
NULL,
};
{
va_list args;
+ if (!log_data.handler)
+ return;
+
va_start(args, format);
log_data.handler(priority, data, file, line, func, format, args);
va_end(args);
LIBEVDEV_EXPORT void
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;
}
/**
* 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
- * logging function is unset.
+ * logging function is unset and no logging is performed.
* @param data User-specific data passed to the log handler.
*
* @note This function may be called before libevdev_set_fd().