Commit 61cc4295 authored by Jan Schmidt's avatar Jan Schmidt

Detect android liblog and use android's log functions for debug output

parent 1600e086
......@@ -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>
......
......@@ -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
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment