Skip to content

Instantly share code, notes, and snippets.

@ikonst
Created August 14, 2012 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikonst/3349719 to your computer and use it in GitHub Desktop.
Save ikonst/3349719 to your computer and use it in GitHub Desktop.
libusb 1.0.9 Android logging patch
--- libusb-1.0.9/libusb/core.c Fri Apr 20 09:44:27 2012
+++ libusb-1.0.9/libusb/core.c Tue Aug 14 17:29:08 2012
@@ -31,6 +31,10 @@
#include <sys/time.h>
#endif
+#ifdef __ANDROID__
+#include <android/log.h>
+#endif
+
#include "libusbi.h"
#if defined(OS_LINUX)
@@ -1768,6 +1772,28 @@
return;
#endif
+#ifdef __ANDROID__
+ int prio;
+ switch (level) {
+ case LOG_LEVEL_INFO:
+ prio = ANDROID_LOG_INFO;
+ break;
+ case LOG_LEVEL_WARNING:
+ prio = ANDROID_LOG_WARN;
+ break;
+ case LOG_LEVEL_ERROR:
+ prio = ANDROID_LOG_ERROR;
+ break;
+ case LOG_LEVEL_DEBUG:
+ prio = ANDROID_LOG_DEBUG;
+ break;
+ default:
+ prio = ANDROID_LOG_UNKNOWN;
+ break;
+ }
+
+ __android_log_vprint(prio, "LibUsb", format, args);
+#else
usbi_gettimeofday(&now, NULL);
if (!first.tv_sec) {
first.tv_sec = now.tv_sec;
@@ -1808,6 +1834,7 @@
vfprintf(stream, format, args);
fprintf(stream, "\n");
+#endif
}
void usbi_log(struct libusb_context *ctx, enum usbi_log_level level,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment