Commit 59d2285c authored by Ryan Pavlik's avatar Ryan Pavlik
Browse files

aux/util: Port logging for Android.

Now if u_logging is used, it goes to logcat.
parent 82037070
......@@ -88,6 +88,7 @@ endif()
find_library(RT_LIBRARY rt)
if(ANDROID)
find_library(ANDROID_LIBRARY android)
find_library(ANDROID_LOG_LIBRARY log)
endif()
# This one is named differently because that's what CTest uses
......
......@@ -199,6 +199,9 @@ if(XRT_HAVE_SYSTEM_CJSON)
else()
target_link_libraries(aux_util PUBLIC xrt-external-cjson)
endif()
if(ANDROID)
target_link_libraries(aux_util PUBLIC ${ANDROID_LOG_LIBRARY})
endif()
# Tracking library.
add_library(aux_tracking STATIC ${TRACKING_SOURCE_FILES})
......
......@@ -8,12 +8,64 @@
*/
#include "util/u_logging.h"
#include "xrt/xrt_config_os.h"
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
#ifdef XRT_OS_ANDROID
#include <android/log.h>
static android_LogPriority
u_log_convert_priority(enum u_logging_level level)
{
switch (level) {
case U_LOGGING_TRACE: return ANDROID_LOG_VERBOSE;
case U_LOGGING_DEBUG: return ANDROID_LOG_DEBUG;
case U_LOGGING_INFO: return ANDROID_LOG_INFO;
case U_LOGGING_WARN: return ANDROID_LOG_WARN;
case U_LOGGING_ERROR: return ANDROID_LOG_ERROR;
case U_LOGGING_RAW: return ANDROID_LOG_INFO;
default: break;
}
return ANDROID_LOG_INFO;
}
void
u_log(const char *file,
int line,
const char *func,
enum u_logging_level level,
const char *format,
...)
{
// print_prefix(func, level);
android_LogPriority prio = u_log_convert_priority(level);
va_list args;
va_start(args, format);
__android_log_vprint(prio, func, format, args);
va_end(args);
}
void
u_log_xdev(const char *file,
int line,
const char *func,
enum u_logging_level level,
struct xrt_device *xdev,
const char *format,
...)
{
android_LogPriority prio = u_log_convert_priority(level);
va_list args;
va_start(args, format);
__android_log_vprint(prio, func, format, args);
va_end(args);
}
#else
/*
*
* Helper functions.
......@@ -81,3 +133,4 @@ u_log_xdev(const char *file,
fprintf(stderr, "\n");
}
#endif
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