Log to stderr by default
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 3 Sep 2013 06:58:29 +0000 (16:58 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 9 Sep 2013 23:37:59 +0000 (09:37 +1000)
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>
libevdev/libevdev.c
libevdev/libevdev.h

index dcf2beb666923429689a7a5b8650134f3a2249e7..aa5cbd667edbf91b0dc12afee808e57fc00eb6e4 100644 (file)
@@ -49,11 +49,32 @@ init_event_queue(struct libevdev *dev)
 }
 
 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);
 }
 
 /*
@@ -61,7 +82,7 @@ libevdev_noop_log_func(enum libevdev_log_priority priority,
  */
 struct logdata log_data = {
        LIBEVDEV_LOG_INFO,
-       libevdev_noop_log_func,
+       libevdev_dflt_log_func,
        NULL,
 };
 
@@ -73,6 +94,9 @@ log_msg(enum libevdev_log_priority priority,
 {
        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);
@@ -137,7 +161,7 @@ libevdev_set_log_handler(struct libevdev *dev, libevdev_log_func_t logfunc)
 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;
 }
 
index 36ecdd100280ff91b15d157ccde8f4976653dfe1..844a1ebe3f915bb33630f0d426105c0e6fe457c1 100644 (file)
@@ -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
- * 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().