jlink: Adjust log verbosity of libjaylink 01/3701/5
authorMarc Schink <openocd-dev@marcschink.de>
Tue, 16 Aug 2016 16:36:27 +0000 (18:36 +0200)
committerPaul Fertser <fercerpav@gmail.com>
Fri, 7 Oct 2016 11:51:47 +0000 (12:51 +0100)
Currently, the log verbosity of libjaylink is not accessible from the
user interface. Therefore, changing the log verbosity of libjaylink is
only possible from within the J-Link driver source code which is not
acceptable for end users.

Output the libjaylink log messages through the logging module of
OpenOCD rather than directly to stderr.

Change-Id: I6bf7bf8f4c8a12fb9e955eeced68224545fa0b5c
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/3701
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
src/jtag/drivers/jlink.c

index 3009058..441e3ef 100644 (file)
@@ -502,6 +502,35 @@ static bool adjust_swd_buffer_size(void)
        return true;
 }
 
+static int jaylink_log_handler(const struct jaylink_context *ctx, int level,
+               const char *format, va_list args, void *user_data)
+{
+       enum log_levels tmp;
+
+       switch (level) {
+       case JAYLINK_LOG_LEVEL_ERROR:
+               tmp = LOG_LVL_ERROR;
+               break;
+       case JAYLINK_LOG_LEVEL_WARNING:
+               tmp = LOG_LVL_WARNING;
+               break;
+       /*
+        * Forward info messages to the debug output because they are more verbose
+        * than info messages of OpenOCD.
+        */
+       case JAYLINK_LOG_LEVEL_INFO:
+       case JAYLINK_LOG_LEVEL_DEBUG:
+               tmp = LOG_LVL_DEBUG;
+               break;
+       default:
+               tmp = LOG_LVL_WARNING;
+       }
+
+       log_vprintf_lf(tmp, __FILE__, __LINE__, __func__, format, args);
+
+       return 0;
+}
+
 static int jlink_init(void)
 {
        int ret;
@@ -523,6 +552,15 @@ static int jlink_init(void)
                return ERROR_JTAG_INIT_FAILED;
        }
 
+       ret = jaylink_log_set_callback(jayctx, &jaylink_log_handler, NULL);
+
+       if (ret != JAYLINK_OK) {
+               LOG_ERROR("jaylink_log_set_callback() failed: %s.",
+                       jaylink_strerror_name(ret));
+               jaylink_exit(jayctx);
+               return ERROR_JTAG_INIT_FAILED;
+       }
+
        ret = jaylink_get_device_list(jayctx, &devs);
 
        if (ret < 0) {