summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Batard <pete@akeo.ie>2012-05-31 18:31:34 +0100
committerPete Batard <pete@akeo.ie>2012-06-04 01:31:06 +0100
commitcf6e68acb116c63f4a8c9d30ee4f2757e8c2e12a (patch)
tree67ebe6a5e6ef82443ded155c801068f8cda3e98d
parenta7ab6bafa952bd8ae2d24a2d0aa89efaab70fc10 (diff)
downloadlibusb-cf6e68acb116c63f4a8c9d30ee4f2757e8c2e12a.tar.gz
Core: Add toggleable debug logging
* Also fix a missing space in debug log messages introduced with the previous timestamp logging update
-rw-r--r--configure.ac4
-rw-r--r--libusb/core.c16
-rw-r--r--libusb/libusbi.h10
-rw-r--r--libusb/os/windows_usb.c2
-rw-r--r--libusb/version_nano.h2
-rw-r--r--msvc/config.h2
6 files changed, 21 insertions, 15 deletions
diff --git a/configure.ac b/configure.ac
index d91d042..96978a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -171,11 +171,11 @@ if test "x$log_enabled" != "xno"; then
fi
AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
- [enable debug logging (default n)])],
+ [start with debug message logging enabled (default n)])],
[debug_log_enabled=$enableval],
[debug_log_enabled='no'])
if test "x$debug_log_enabled" != "xno"; then
- AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Debug message logging])
+ AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Start with debug message logging enabled])
fi
# Examples build
diff --git a/libusb/core.c b/libusb/core.c
index 6540fd3..d4ff789 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -1634,12 +1634,22 @@ int API_EXPORTED libusb_init(libusb_context **context)
}
memset(ctx, 0, sizeof(*ctx));
+#ifdef ENABLE_DEBUG_LOGGING
+ ctx->debug = LOG_LEVEL_DEBUG;
+#endif
+
if (dbg) {
ctx->debug = atoi(dbg);
if (ctx->debug)
ctx->debug_fixed = 1;
}
+ /* default context should be initialized before calling usbi_dbg */
+ if (!usbi_default_context) {
+ usbi_default_context = ctx;
+ usbi_dbg("created default context");
+ }
+
usbi_dbg("");
if (usbi_backend->init) {
@@ -1793,6 +1803,8 @@ void usbi_log_v(struct libusb_context *ctx, enum usbi_log_level level,
global_debug = 1;
#else
USBI_GET_CONTEXT(ctx);
+ if (ctx == NULL)
+ return;
global_debug = (ctx->debug == LOG_LEVEL_DEBUG);
if (!ctx->debug)
return;
@@ -1800,6 +1812,8 @@ void usbi_log_v(struct libusb_context *ctx, enum usbi_log_level level,
return;
if (level == LOG_LEVEL_INFO && ctx->debug < LOG_LEVEL_INFO)
return;
+ if (level == LOG_LEVEL_DEBUG && ctx->debug < LOG_LEVEL_DEBUG)
+ return;
#endif
usbi_gettimeofday(&now, NULL);
@@ -1836,7 +1850,7 @@ void usbi_log_v(struct libusb_context *ctx, enum usbi_log_level level,
}
if (global_debug) {
- fprintf(stderr, "[%2d.%06d] [%08x] libusbx: %s [%s]",
+ fprintf(stderr, "[%2d.%06d] [%08x] libusbx: %s [%s] ",
(int)now.tv_sec, (int)now.tv_usec, usbi_get_tid(), prefix, function);
} else {
fprintf(stderr, "libusbx: %s [%s] ", prefix, function);
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 41a6ba1..9de56a1 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -129,13 +129,9 @@ void usbi_log_v(struct libusb_context *ctx, enum usbi_log_level level,
#ifdef ENABLE_LOGGING
#define _usbi_log(ctx, level, ...) usbi_log(ctx, level, __FUNCTION__, __VA_ARGS__)
-#else
-#define _usbi_log(ctx, level, ...) do { (void)(ctx); } while(0)
-#endif
-
-#ifdef ENABLE_DEBUG_LOGGING
#define usbi_dbg(...) _usbi_log(NULL, LOG_LEVEL_DEBUG, __VA_ARGS__)
#else
+#define _usbi_log(ctx, level, ...) do { (void)(ctx); } while(0)
#define usbi_dbg(...) do {} while(0)
#endif
@@ -168,11 +164,7 @@ static inline void usbi_err( struct libusb_context *ctx, const char *format,
LOG_BODY(ctx,LOG_LEVEL_ERROR)
static inline void usbi_dbg(const char *format, ...)
-#ifdef ENABLE_DEBUG_LOGGING
LOG_BODY(NULL,LOG_LEVEL_DEBUG)
-#else
-{ }
-#endif
#endif /* !defined(_MSC_VER) || _MSC_VER >= 1400 */
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index 1d9a80b..dbebfaf 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -129,7 +129,7 @@ static inline BOOLEAN guid_eq(const GUID *guid1, const GUID *guid2) {
return false;
}
-#if defined(ENABLE_DEBUG_LOGGING) || (defined(_MSC_VER) && _MSC_VER < 1400)
+#if defined(ENABLE_LOGGING)
static char* guid_to_string(const GUID* guid)
{
static char guid_string[MAX_GUID_STRING_LENGTH];
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 9687da3..264a5e3 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 10518
+#define LIBUSB_NANO 10519
diff --git a/msvc/config.h b/msvc/config.h
index 43b4d4e..e14d91d 100644
--- a/msvc/config.h
+++ b/msvc/config.h
@@ -8,7 +8,7 @@
/* Default visibility */
#define DEFAULT_VISIBILITY /**/
-/* Debug message logging */
+/* Start with debug message logging enabled */
//#define ENABLE_DEBUG_LOGGING 1
/* Message logging */