summaryrefslogtreecommitdiff
path: root/sal/osl
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2013-03-01 10:52:30 +0200
committerTor Lillqvist <tml@iki.fi>2013-03-01 10:55:46 +0200
commit6a1cb54c31a0e7591173afa167938535bbe5cf6e (patch)
treea94f0a96c76305179e1c7a662519303349050928 /sal/osl
parent742bb0ebe3f309c372934397acb463b4e172b4bf (diff)
Pass log output directly to the Android log mechanism
Writing to stderr just takes a detour through the pipe we set up ourselves and read in a separate thread, and eventually ends up being passed to __android_log_print() anyway. Change-Id: I46356910e48926f22c8dc88d9eba6acbc8bce751
Diffstat (limited to 'sal/osl')
-rw-r--r--sal/osl/all/log.cxx37
1 files changed, 34 insertions, 3 deletions
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index c084bddbe5af..fcf0a1702271 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -62,6 +62,10 @@
bool sal_use_syslog;
#endif
+#ifdef ANDROID
+#include <android/log.h>
+#endif
+
// Avoid the use of other sal code in this file as much as possible, so that
// this code can be called from other sal code without causing endless
// recursion.
@@ -209,27 +213,54 @@ void log(
char const * message)
{
std::ostringstream s;
+#ifndef ANDROID
#ifdef HAVE_SYSLOG_H
if (!sal_use_syslog)
#endif
s << toString(level) << ':';
+#endif
if (level == SAL_DETAIL_LOG_LEVEL_DEBUG) {
- s << /*no where*/' ' << message << '\n';
+ s << /*no area or where */ ' ' << message << '\n';
} else {
- s << area << ':' << OSL_DETAIL_GETPID << ':'
- << osl::Thread::getCurrentIdentifier() << ':';
+#ifdef ANDROID
+ // The area will be used as the "tag", and log info already contgains the pid on Android
+#else
+ s << area << ':' << OSL_DETAIL_GETPID << ':';
+#endif
+ s << osl::Thread::getCurrentIdentifier() << ':';
if (strncmp(where, SRCDIR, sizeof(SRCDIR)-1) == 0)
s << where+sizeof(SRCDIR);
else
s << where;
s << message << '\n';
}
+#ifdef ANDROID
+ int android_log_level;
+ switch (level) {
+ case SAL_DETAIL_LOG_LEVEL_INFO:
+ android_log_level = ANDROID_LOG_INFO;
+ break;
+ case SAL_DETAIL_LOG_LEVEL_WARN:
+ android_log_level = ANDROID_LOG_WARN;
+ break;
+ case SAL_DETAIL_LOG_LEVEL_DEBUG:
+ android_log_level = ANDROID_LOG_DEBUG;
+ break;
+ default:
+ android_log_level = ANDROID_LOG_INFO;
+ break;
+ }
+ if (area == NULL)
+ area = "LibreOffice";
+ __android_log_print(android_log_level, area, "%s", s.str().c_str());
+#else
#ifdef HAVE_SYSLOG_H
if (sal_use_syslog)
syslog(toSyslogPriority(level), "%s", s.str().c_str());
else
#endif
std::fputs(s.str().c_str(), stderr);
+#endif
}
}