diff options
author | Pete Batard <pete@akeo.ie> | 2012-05-31 18:31:34 +0100 |
---|---|---|
committer | Pete Batard <pete@akeo.ie> | 2012-06-04 01:31:06 +0100 |
commit | cf6e68acb116c63f4a8c9d30ee4f2757e8c2e12a (patch) | |
tree | 67ebe6a5e6ef82443ded155c801068f8cda3e98d /libusb/core.c | |
parent | a7ab6bafa952bd8ae2d24a2d0aa89efaab70fc10 (diff) | |
download | libusbx-cf6e68acb116c63f4a8c9d30ee4f2757e8c2e12a.tar.gz |
Core: Add toggleable debug logging
* Also fix a missing space in debug log messages introduced
with the previous timestamp logging update
Diffstat (limited to 'libusb/core.c')
-rw-r--r-- | libusb/core.c | 16 |
1 files changed, 15 insertions, 1 deletions
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); |