aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/LogBackend.cxx35
-rw-r--r--src/LogInit.cxx31
2 files changed, 65 insertions, 1 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 */
}
diff --git a/src/LogInit.cxx b/src/LogInit.cxx
index 38dd5356b..c80d4575f 100644
--- a/src/LogInit.cxx
+++ b/src/LogInit.cxx
@@ -49,6 +49,8 @@
static constexpr Domain log_domain("log");
+#ifndef ANDROID
+
static int out_fd;
static AllocatedPath out_path = AllocatedPath::Null();
@@ -101,16 +103,29 @@ parse_log_level(const char *value, unsigned line)
}
}
+#endif
+
void
log_early_init(bool verbose)
{
+#ifdef ANDROID
+ (void)verbose;
+#else
if (verbose)
SetLogThreshold(LogLevel::DEBUG);
+#endif
}
bool
log_init(bool verbose, bool use_stdout, Error &error)
{
+#ifdef ANDROID
+ (void)verbose;
+ (void)use_stdout;
+ (void)error;
+
+ return true;
+#else
const struct config_param *param;
#ifdef HAVE_GLIB
@@ -151,8 +166,11 @@ log_init(bool verbose, bool use_stdout, Error &error)
log_init_file(param->line, error);
}
}
+#endif
}
+#ifndef ANDROID
+
static void
close_log_files(void)
{
@@ -161,16 +179,22 @@ close_log_files(void)
#endif
}
+#endif
+
void
log_deinit(void)
{
+#ifndef ANDROID
close_log_files();
out_path = AllocatedPath::Null();
+#endif
}
-
void setup_log_output(bool use_stdout)
{
+#ifdef ANDROID
+ (void)use_stdout;
+#else
if (use_stdout)
return;
@@ -193,10 +217,14 @@ void setup_log_output(bool use_stdout)
#ifdef HAVE_GLIB
SetLogCharset(nullptr);
#endif
+#endif
}
int cycle_log_files(void)
{
+#ifdef ANDROID
+ return 0;
+#else
int fd;
if (out_path.IsNull())
@@ -217,4 +245,5 @@ int cycle_log_files(void)
redirect_logs(fd);
FormatDebug(log_domain, "Done cycling log files");
return 0;
+#endif
}