Since the next item on the agenda will be toggleable logging, we might as well take care of some minor logging improvements beforehand.

This patch moves the definition of the logging levels from libusbi.h to libusb.h.

The idea is that since we provide a libusb_set_debug() call that takes a level parameter, we probably want to make that parameter more user friendly by defining the various levels we use. This will also make an application's code a more explicit with regards to its logging intentions.

Regards,

/Pete
>From d3f46a466424caf620e0f107cfce24615fbd7eb1 Mon Sep 17 00:00:00 2001
From: Pete Batard <p...@akeo.ie>
Date: Thu, 24 May 2012 13:36:23 +0100
Subject: [PATCH 1/2] Core: Define log levels in libusb.h

* Also update xusb sample to use these levels
---
 examples/xusb.c       |    3 +--
 libusb/core.c         |   24 ++++++++++--------------
 libusb/libusb.h       |   18 ++++++++++++++++++
 libusb/libusbi.h      |    7 -------
 4 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/examples/xusb.c b/examples/xusb.c
index d775781..08de6ba 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -851,8 +851,7 @@ int main(int argc, char** argv)
        if (r < 0)
                return r;
 
-       // Info = 3, Debug = 4
-       libusb_set_debug(NULL, debug_mode?4:3);
+       libusb_set_debug(NULL, debug_mode?LOG_LEVEL_DEBUG:LOG_LEVEL_INFO);
 
        test_device(VID, PID);
 
diff --git a/libusb/core.c b/libusb/core.c
index 6defd0a..e6f2f82 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -1563,20 +1563,16 @@ int API_EXPORTED 
libusb_attach_kernel_driver(libusb_device_handle *dev,
 }
 
 /** \ingroup lib
- * Set message verbosity.
- *  - Level 0: no messages ever printed by the library (default)
- *  - Level 1: error messages are printed to stderr
- *  - Level 2: warning and error messages are printed to stderr
- *  - Level 3: informational messages are printed to stdout, warning and error
- *    messages are printed to stderr
+ * Set log message verbosity.
  *
- * The default level is 0, which means no messages are ever printed. If you
- * choose to increase the message verbosity level, ensure that your
- * application does not close the stdout/stderr file descriptors.
+ * The default level is \ref LOG_LEVEL_NONE, which means no messages are ever
+ * printed. If you choose to increase the message verbosity level, ensure
+ * that your application does not close the stdout/stderr file descriptors.
  *
- * You are advised to set level 3. libusbx is conservative with its message
- * logging and most of the time, will only log messages that explain error
- * conditions and other oddities. This will help you debug your software.
+ * You are advised to use level \ref LOG_LEVEL_WARNING. libusbx is conservative
+ * with its message logging and most of the time, will only log messages that
+ * explain error conditions and other oddities. This will help you debug
+ * your software.
  *
  * If the LIBUSB_DEBUG environment variable was set when libusbx was
  * initialized, this function does nothing: the message verbosity is fixed
@@ -1791,9 +1787,9 @@ void usbi_log_v(struct libusb_context *ctx, enum 
usbi_log_level level,
        USBI_GET_CONTEXT(ctx);
        if (!ctx->debug)
                return;
-       if (level == LOG_LEVEL_WARNING && ctx->debug < 2)
+       if (level == LOG_LEVEL_WARNING && ctx->debug < LOG_LEVEL_WARNING)
                return;
-       if (level == LOG_LEVEL_INFO && ctx->debug < 3)
+       if (level == LOG_LEVEL_INFO && ctx->debug < LOG_LEVEL_INFO)
                return;
 #endif
 
diff --git a/libusb/libusb.h b/libusb/libusb.h
index 4887b80..fd231ea 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -949,6 +949,24 @@ enum libusb_capability {
        LIBUSB_CAP_HAS_CAPABILITY = 0,
 };
 
+/** \ingroup lib
+ *  Log message levels.
+ *  - LOG_LEVEL_NONE (0)    : no messages ever printed by the library (default)
+ *  - LOG_LEVEL_ERROR (1)   : error messages are printed to stderr
+ *  - LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr
+ *  - LOG_LEVEL_INFO (3)    : informational messages are printed to stdout, 
warning
+ *    and error messages are printed to stderr
+ *  - LOG_LEVEL_DEBUG (4)   : debug and informational messages are printed to 
stdout,
+ *    warnings and errors to stderr
+ */
+enum usbi_log_level {
+       LOG_LEVEL_NONE = 0,
+       LOG_LEVEL_ERROR,
+       LOG_LEVEL_WARNING,
+       LOG_LEVEL_INFO,
+       LOG_LEVEL_DEBUG,
+};
+
 int LIBUSB_CALL libusb_init(libusb_context **ctx);
 void LIBUSB_CALL libusb_exit(libusb_context *ctx);
 void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 8623862..41a6ba1 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -119,13 +119,6 @@ static inline void list_del(struct list_head *entry)
 
 #define TIMESPEC_IS_SET(ts) ((ts)->tv_sec != 0 || (ts)->tv_nsec != 0)
 
-enum usbi_log_level {
-       LOG_LEVEL_DEBUG,
-       LOG_LEVEL_INFO,
-       LOG_LEVEL_WARNING,
-       LOG_LEVEL_ERROR,
-};
-
 void usbi_log(struct libusb_context *ctx, enum usbi_log_level level,
        const char *function, const char *format, ...);
 
-- 
1.7.10.msysgit.1

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to