Core: Define log levels in libusb.h

* Also update xusb sample to use these levels
This commit is contained in:
Pete Batard 2012-05-24 13:36:23 +01:00
parent 9ec54b6919
commit 933a319469
5 changed files with 30 additions and 24 deletions

View file

@ -851,8 +851,7 @@ int main(int argc, char** argv)
if (r < 0) if (r < 0)
return r; return r;
// Info = 3, Debug = 4 libusb_set_debug(NULL, debug_mode?LOG_LEVEL_DEBUG:LOG_LEVEL_INFO);
libusb_set_debug(NULL, debug_mode?4:3);
test_device(VID, PID); test_device(VID, PID);

View file

@ -1563,20 +1563,16 @@ int API_EXPORTED libusb_attach_kernel_driver(libusb_device_handle *dev,
} }
/** \ingroup lib /** \ingroup lib
* Set message verbosity. * Set log 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
* *
* The default level is 0, which means no messages are ever printed. If you * The default level is \ref LOG_LEVEL_NONE, which means no messages are ever
* choose to increase the message verbosity level, ensure that your * printed. If you choose to increase the message verbosity level, ensure
* application does not close the stdout/stderr file descriptors. * that your application does not close the stdout/stderr file descriptors.
* *
* You are advised to set level 3. libusbx is conservative with its message * You are advised to use level \ref LOG_LEVEL_WARNING. libusbx is conservative
* logging and most of the time, will only log messages that explain error * with its message logging and most of the time, will only log messages that
* conditions and other oddities. This will help you debug your software. * explain error conditions and other oddities. This will help you debug
* your software.
* *
* If the LIBUSB_DEBUG environment variable was set when libusbx was * If the LIBUSB_DEBUG environment variable was set when libusbx was
* initialized, this function does nothing: the message verbosity is fixed * 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); USBI_GET_CONTEXT(ctx);
if (!ctx->debug) if (!ctx->debug)
return; return;
if (level == LOG_LEVEL_WARNING && ctx->debug < 2) if (level == LOG_LEVEL_WARNING && ctx->debug < LOG_LEVEL_WARNING)
return; return;
if (level == LOG_LEVEL_INFO && ctx->debug < 3) if (level == LOG_LEVEL_INFO && ctx->debug < LOG_LEVEL_INFO)
return; return;
#endif #endif

View file

@ -949,6 +949,24 @@ enum libusb_capability {
LIBUSB_CAP_HAS_CAPABILITY = 0, 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); int LIBUSB_CALL libusb_init(libusb_context **ctx);
void LIBUSB_CALL libusb_exit(libusb_context *ctx); void LIBUSB_CALL libusb_exit(libusb_context *ctx);
void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level); void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);

View file

@ -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) #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, void usbi_log(struct libusb_context *ctx, enum usbi_log_level level,
const char *function, const char *format, ...); const char *function, const char *format, ...);

View file

@ -1 +1 @@
#define LIBUSB_NANO 10509 #define LIBUSB_NANO 10510