From 6a1cb54c31a0e7591173afa167938535bbe5cf6e Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Fri, 1 Mar 2013 10:52:30 +0200 Subject: 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 --- sal/osl/all/log.cxx | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'sal') 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 +#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 } } -- cgit