From b68a37b8356d003efd045d4ca44428ab66dd8f73 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 2 Mar 2013 23:41:43 +0100 Subject: [PATCH] Replace usb_set_debug() in utils by new group in LIBNFC_LOG_LEVEL To use it: (NFC_LOG_PRIORITY_DEBUG * 2 ^ NFC_LOG_GROUP_LIBUSB) LIBUSB_LOG_LEVEL=12288 --- libnfc/buses/usbbus.c | 10 ++++++++++ libnfc/log.h | 1 + utils/nfc-list.c | 12 ------------ utils/nfc-scan-device.c | 12 ------------ 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/libnfc/buses/usbbus.c b/libnfc/buses/usbbus.c index 6c0abdd..a3e2f99 100644 --- a/libnfc/buses/usbbus.c +++ b/libnfc/buses/usbbus.c @@ -38,6 +38,16 @@ int usb_prepare(void) if (usb_initialized) { return 0; } + +#ifdef ENVVARS + char *env_log_level = getenv("LIBNFC_LOG_LEVEL"); + // Set libusb debug only if asked explicitely: + // LIBUSB_LOG_LEVEL=12288 (= NFC_LOG_PRIORITY_DEBUG * 2 ^ NFC_LOG_GROUP_LIBUSB) + if (env_log_level && (((atoi(env_log_level) >> (NFC_LOG_GROUP_LIBUSB * 2)) & 0x00000003) >= NFC_LOG_PRIORITY_DEBUG)) { + setenv("USB_DEBUG", "255", 1); + } +#endif + usb_init(); usb_initialized = true; diff --git a/libnfc/log.h b/libnfc/log.h index e5ab1ca..d3604fa 100644 --- a/libnfc/log.h +++ b/libnfc/log.h @@ -35,6 +35,7 @@ #define NFC_LOG_GROUP_CHIP 3 #define NFC_LOG_GROUP_DRIVER 4 #define NFC_LOG_GROUP_COM 5 +#define NFC_LOG_GROUP_LIBUSB 6 /* To enable log only for one (or more) group, you can use this formula: diff --git a/utils/nfc-list.c b/utils/nfc-list.c index ca49be9..380120d 100644 --- a/utils/nfc-list.c +++ b/utils/nfc-list.c @@ -38,12 +38,6 @@ # include "config.h" #endif // HAVE_CONFIG_H -#ifdef HAVE_LIBUSB -# ifdef DEBUG -# include -# endif -#endif - #include #include #include @@ -90,12 +84,6 @@ main(int argc, const char *argv[]) } } -#ifdef HAVE_LIBUSB -# ifdef DEBUG - usb_set_debug(4); -# endif -#endif - /* Lazy way to open an NFC device */ #if 0 pnd = nfc_open(context, NULL); diff --git a/utils/nfc-scan-device.c b/utils/nfc-scan-device.c index 12693b1..04eae0d 100644 --- a/utils/nfc-scan-device.c +++ b/utils/nfc-scan-device.c @@ -38,12 +38,6 @@ # include "config.h" #endif // HAVE_CONFIG_H -#ifdef HAVE_LIBUSB -# ifdef DEBUG -# include -# endif -#endif - #include #include #include @@ -101,12 +95,6 @@ main(int argc, const char *argv[]) acLibnfcVersion = nfc_version(); printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); -#ifdef HAVE_LIBUSB -# ifdef DEBUG - usb_set_debug(4); -# endif -#endif - nfc_connstring connstrings[MAX_DEVICE_COUNT]; size_t szDeviceFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);