From 90114514a9d9439f7ed9519f2956bb00942771c5 Mon Sep 17 00:00:00 2001 From: Max Kellermann <max@duempel.org> Date: Fri, 21 Feb 2014 22:52:19 +0100 Subject: LogBackend: use __android_log_print() on Android --- src/LogBackend.cxx | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/LogBackend.cxx') diff --git a/src/LogBackend.cxx b/src/LogBackend.cxx index ba37c1dbb..3cd907179 100644 --- a/src/LogBackend.cxx +++ b/src/LogBackend.cxx @@ -36,6 +36,33 @@ #include <syslog.h> #endif +#ifdef ANDROID +#include <android/log.h> + +static int +ToAndroidLogLevel(LogLevel log_level) +{ + switch (log_level) { + case LogLevel::DEBUG: + return ANDROID_LOG_DEBUG; + + case LogLevel::INFO: + case LogLevel::DEFAULT: + return ANDROID_LOG_INFO; + + case LogLevel::WARNING: + return ANDROID_LOG_WARN; + + case LogLevel::ERROR: + return ANDROID_LOG_ERROR; + } + + assert(false); + gcc_unreachable(); +} + +#else + static LogLevel log_threshold = LogLevel::INFO; #ifdef HAVE_GLIB @@ -176,9 +203,16 @@ FileLog(const Domain &domain, const char *message) #endif } +#endif /* !ANDROID */ + void Log(const Domain &domain, LogLevel level, const char *msg) { +#ifdef ANDROID + __android_log_print(ToAndroidLogLevel(level), "MPD", + "%s: %s", domain.GetName(), msg); +#else + if (level < log_threshold) return; @@ -190,4 +224,5 @@ Log(const Domain &domain, LogLevel level, const char *msg) #endif FileLog(domain, msg); +#endif /* !ANDROID */ } -- cgit v1.2.3