aboutsummaryrefslogtreecommitdiffstats
path: root/src/LogBackend.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-21 22:52:19 +0100
committerMax Kellermann <max@duempel.org>2014-02-22 00:18:46 +0100
commit90114514a9d9439f7ed9519f2956bb00942771c5 (patch)
treea20e96f56ceb07c6426c147df40ec04b988d69c8 /src/LogBackend.cxx
parent7757e59e7874ed160702483bbbd62c518e8195eb (diff)
downloadmpd-90114514a9d9439f7ed9519f2956bb00942771c5.tar.gz
mpd-90114514a9d9439f7ed9519f2956bb00942771c5.tar.xz
mpd-90114514a9d9439f7ed9519f2956bb00942771c5.zip
LogBackend: use __android_log_print() on Android
Diffstat (limited to 'src/LogBackend.cxx')
-rw-r--r--src/LogBackend.cxx35
1 files changed, 35 insertions, 0 deletions
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 */
}