diff options
author | Jan Schmidt <jan@centricular.com> | 2014-08-26 13:10:04 +1000 |
---|---|---|
committer | Jan Schmidt <jan@centricular.com> | 2014-08-26 15:32:02 +1000 |
commit | 61cc4295b1c129040a69260663ae3e5453a22adc (patch) | |
tree | b60176d4ba055a45ae8c095a8b8c80f7c2bf38b6 | |
parent | 1600e08668fd5fa21f448a3d824c055f2cee4352 (diff) | |
download | orc-61cc4295b1c129040a69260663ae3e5453a22adc.tar.gz |
Detect android liblog and use android's log functions for debug output
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | orc/Makefile.am | 2 | ||||
-rw-r--r-- | orc/orcdebug.c | 45 |
3 files changed, 53 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 32791fe..69492c9 100644 --- a/configure.ac +++ b/configure.ac @@ -77,6 +77,13 @@ AC_CHECK_LIB(rt, clock_gettime, ) AC_SUBST(LIBRT) +dnl Android liblog +AC_CHECK_LIB(log, __android_log_print, + AC_DEFINE(HAVE_ANDROID_LIBLOG, 1, [Defined if we have __android_log_print()]) + LIBLOG=-llog + ) +AC_SUBST(LIBLOG) + AC_CACHE_CHECK(for monotonic clocks, orc_cv_monotonic_clock,AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ #include <time.h> diff --git a/orc/Makefile.am b/orc/Makefile.am index 82973e6..84c36cd 100644 --- a/orc/Makefile.am +++ b/orc/Makefile.am @@ -3,7 +3,7 @@ pkgincludedir = $(includedir)/orc-@ORC_MAJORMINOR@/orc lib_LTLIBRARIES = liborc-@ORC_MAJORMINOR@.la -liborc_@ORC_MAJORMINOR@_la_LIBADD = $(LIBM) $(LIBRT) $(PTHREAD_LIBS) +liborc_@ORC_MAJORMINOR@_la_LIBADD = $(LIBM) $(LIBRT) $(PTHREAD_LIBS) $(LIBLOG) liborc_@ORC_MAJORMINOR@_la_LDFLAGS = $(ORC_LDFLAGS) liborc_@ORC_MAJORMINOR@_la_CFLAGS = $(ORC_CFLAGS) \ -DORC_ENABLE_UNSTABLE_API diff --git a/orc/orcdebug.c b/orc/orcdebug.c index c4aa7be..2e69464 100644 --- a/orc/orcdebug.c +++ b/orc/orcdebug.c @@ -35,6 +35,10 @@ #include <stdarg.h> #include <stdlib.h> +#ifdef HAVE_ANDROID_LIBLOG +#include <android/log.h> +#endif + /** * SECTION:orcdebug * @title: OrcDebug @@ -66,6 +70,46 @@ _orc_debug_init(void) ORC_INFO ("orc-" VERSION " debug init"); } +#ifdef HAVE_ANDROID_LIBLOG +static void +orc_debug_print_valist (int level, const char *file, const char *func, + int line, const char *format, va_list args) +{ + int android_log_level; + char *dbg; + + if (level > orc_debug_get_level()) + return; + + switch (level) { + case ORC_DEBUG_ERROR: + android_log_level = ANDROID_LOG_ERROR; + break; + case ORC_DEBUG_WARNING: + android_log_level = ANDROID_LOG_WARN; + break; + case ORC_DEBUG_INFO: + android_log_level = ANDROID_LOG_INFO; + break; + case ORC_DEBUG_LOG: + android_log_level = ANDROID_LOG_DEBUG; + break; + default: + android_log_level = ANDROID_LOG_VERBOSE; + break; + } + + if (vasprintf (&dbg, format, args) < 0) { + __android_log_print (android_log_level, "Orc", "Failed to alloc debug string...."); + return; + } + + __android_log_print (android_log_level, "Orc", + "%s:%d:%s %s\n", file, line, func, dbg); + + free (dbg); +} +#else static void orc_debug_print_valist (int level, const char *file, const char *func, int line, const char *format, va_list args) @@ -84,6 +128,7 @@ orc_debug_print_valist (int level, const char *file, const char *func, vfprintf (stderr, format, args); fprintf (stderr, "\n"); } +#endif void orc_debug_print (int level, const char *file, const char *func, |