From: Marc Schink Date: Tue, 16 Aug 2016 16:36:27 +0000 (+0200) Subject: jlink: Adjust log verbosity of libjaylink X-Git-Tag: v0.10.0-rc1~92 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8515da60a80880db1f4c632a1ecfef383f6136d8;p=openocd jlink: Adjust log verbosity of libjaylink 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 Reviewed-on: http://openocd.zylin.com/3701 Tested-by: jenkins Reviewed-by: Paul Fertser --- diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index 30090582..441e3efa 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -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) {