summaryrefslogtreecommitdiff
path: root/ACE/ace
diff options
context:
space:
mode:
authorFred Hornsey <hornseyf@objectcomputing.com>2019-02-11 19:05:11 -0600
committerFred Hornsey <hornseyf@objectcomputing.com>2019-02-11 19:05:11 -0600
commit4d7e8de04c5b1f76bf29c699d98647e9fd00d212 (patch)
tree1d8e8418fcd4b4aabc410f27ab7720435d4d01f9 /ACE/ace
parent8d35eb8b12f4a9bae490620d5a0cf52d7f8f717e (diff)
downloadATCD-4d7e8de04c5b1f76bf29c699d98647e9fd00d212.tar.gz
Use Logcat on Android
On Android stdout and stderr are discarded by default. It's possible to workaround this but it's not pretty. The best solution is to use Android's logging system, Logcat. I've added an ACE_Log_Msg_Backend, ACE_Log_Msg_Android_Logcat, and set it to be the default output on Android.
Diffstat (limited to 'ACE/ace')
-rw-r--r--ACE/ace/Log_Msg.cpp11
-rw-r--r--ACE/ace/Log_Msg.h10
-rw-r--r--ACE/ace/Log_Msg_Android_Logcat.cpp81
-rw-r--r--ACE/ace/Log_Msg_Android_Logcat.h59
-rw-r--r--ACE/ace/ace.mpc1
5 files changed, 155 insertions, 7 deletions
diff --git a/ACE/ace/Log_Msg.cpp b/ACE/ace/Log_Msg.cpp
index 535d567d0a5..65fc56ab8b7 100644
--- a/ACE/ace/Log_Msg.cpp
+++ b/ACE/ace/Log_Msg.cpp
@@ -80,11 +80,12 @@ public:
#if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) && !defined (ACE_HAS_PHARLAP)
# define ACE_LOG_MSG_SYSLOG_BACKEND ACE_Log_Msg_NT_Event_Log
+#elif defined (ACE_ANDROID)
+# include "ace/Log_Msg_Android_Logcat.h"
+# define ACE_LOG_MSG_SYSLOG_BACKEND ACE_Log_Msg_Android_Logcat
#elif !defined (ACE_LACKS_UNIX_SYSLOG) && !defined (ACE_HAS_WINCE)
# define ACE_LOG_MSG_SYSLOG_BACKEND ACE_Log_Msg_UNIX_Syslog
-#else
-# define ACE_LOG_MSG_SYSLOG_BACKEND ACE_Log_Msg_IPC
-#endif /* ! ACE_WIN32 */
+#endif
// When doing ACE_OS::s[n]printf() calls in log(), we need to update
// the space remaining in the output buffer based on what's returned from
@@ -166,14 +167,14 @@ int ACE_Log_Msg_Manager::init_backend (const u_long *flags)
if (ACE_Log_Msg_Manager::log_backend_ == 0)
{
-#if (defined (WIN32) || !defined (ACE_LACKS_UNIX_SYSLOG)) && !defined (ACE_HAS_WINCE) && !defined (ACE_HAS_PHARLAP)
+#ifdef ACE_LOG_MSG_SYSLOG_BACKEND
// Allocate the ACE_Log_Msg_Backend instance.
if (ACE_BIT_ENABLED (ACE_Log_Msg_Manager::log_backend_flags_, ACE_Log_Msg::SYSLOG))
ACE_NEW_RETURN (ACE_Log_Msg_Manager::log_backend_,
ACE_LOG_MSG_SYSLOG_BACKEND,
-1);
else
-#endif /* defined (WIN32) && !defined (ACE_HAS_WINCE) && !defined (ACE_HAS_PHARLAP) */
+#endif
ACE_NEW_RETURN (ACE_Log_Msg_Manager::log_backend_,
ACE_Log_Msg_IPC,
-1);
diff --git a/ACE/ace/Log_Msg.h b/ACE/ace/Log_Msg.h
index 2aac2fe0167..23df6856bb2 100644
--- a/ACE/ace/Log_Msg.h
+++ b/ACE/ace/Log_Msg.h
@@ -161,6 +161,12 @@
# undef THREAD
#endif /* THREAD */
+#ifdef ACE_ANDROID
+#define ACE_DEFAULT_LOG_FLAGS ACE_Log_Msg::SYSLOG
+#else
+#define ACE_DEFAULT_LOG_FLAGS ACE_Log_Msg::STDERR
+#endif
+
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
class ACE_Log_Msg_Callback;
@@ -234,7 +240,7 @@ public:
SYSLOG = 128,
/// Write messages to the user provided backend
CUSTOM = 256
- };
+ };
// = Initialization and termination routines.
@@ -284,7 +290,7 @@ public:
* @a logger_key is 0, @a prog_name is used.
*/
int open (const ACE_TCHAR *prog_name,
- u_long options_flags = ACE_Log_Msg::STDERR,
+ u_long options_flags = ACE_DEFAULT_LOG_FLAGS,
const ACE_TCHAR *logger_key = 0);
// = Set/get the options flags.
diff --git a/ACE/ace/Log_Msg_Android_Logcat.cpp b/ACE/ace/Log_Msg_Android_Logcat.cpp
new file mode 100644
index 00000000000..8fc517be099
--- /dev/null
+++ b/ACE/ace/Log_Msg_Android_Logcat.cpp
@@ -0,0 +1,81 @@
+#include "ace/config-all.h"
+
+#ifdef ACE_ANDROID
+
+#include <android/log.h> // Android Logging Functions
+
+#include "ace/ACE.h"
+#include "ace/Log_Category.h"
+#include "ace/Log_Msg_Android_Logcat.h"
+#include "ace/Log_Record.h"
+#include "ace/OS_NS_string.h"
+
+ACE_BEGIN_VERSIONED_NAMESPACE_DECL
+
+/**
+ * Convert ACE Log Priority to Android Logcat Priority
+ */
+static android_LogPriority
+convert_log_priority (ACE_Log_Priority lm_priority)
+{
+ switch (lm_priority) {
+ case LM_TRACE:
+ case LM_DEBUG:
+ return ANDROID_LOG_DEBUG;
+ case LM_STARTUP:
+ case LM_SHUTDOWN:
+ case LM_INFO:
+ case LM_NOTICE:
+ return ANDROID_LOG_INFO;
+ case LM_WARNING:
+ return ANDROID_LOG_WARN;
+ case LM_CRITICAL:
+ case LM_ALERT:
+ case LM_EMERGENCY:
+ return ANDROID_LOG_FATAL;
+ case LM_ERROR:
+ default:
+ return ANDROID_LOG_ERROR;
+ }
+}
+
+ACE_Log_Msg_Android_Logcat::ACE_Log_Msg_Android_Logcat ()
+{
+}
+
+ACE_Log_Msg_Android_Logcat::~ACE_Log_Msg_Android_Logcat (void)
+{
+ this->close ();
+}
+
+int
+ACE_Log_Msg_Android_Logcat::open (const ACE_TCHAR * logger_key)
+{
+ return 0;
+}
+
+int
+ACE_Log_Msg_Android_Logcat::reset (void)
+{
+ return close ();
+}
+
+int
+ACE_Log_Msg_Android_Logcat::close (void)
+{
+ return 0;
+}
+
+ssize_t
+ACE_Log_Msg_Android_Logcat::log (ACE_Log_Record &log_record)
+{
+ __android_log_write (
+ convert_log_priority (static_cast<ACE_Log_Priority> (log_record.type ())),
+ "ACE",
+ log_record.msg_data ());
+ return 0;
+}
+
+ACE_END_VERSIONED_NAMESPACE_DECL
+
+#endif
diff --git a/ACE/ace/Log_Msg_Android_Logcat.h b/ACE/ace/Log_Msg_Android_Logcat.h
new file mode 100644
index 00000000000..8eb9c266272
--- /dev/null
+++ b/ACE/ace/Log_Msg_Android_Logcat.h
@@ -0,0 +1,59 @@
+/**
+ * @file Log_Msg_Android_Logcat.h
+ *
+ * @author Frederick Hornsey <hornseyf@objectcomputing.com>
+ */
+
+#ifndef ACE_LOG_MSG_ANDROID_LOGCAT_H
+#define ACE_LOG_MSG_ANDROID_LOGCAT_H
+
+#include /**/ "ace/pre.h"
+
+#include /**/ "ace/config-all.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#ifdef ACE_ANDROID
+
+#include "ace/Log_Msg_Backend.h"
+#include "ace/Basic_Types.h"
+
+ACE_BEGIN_VERSIONED_NAMESPACE_DECL
+
+/**
+ * @class ACE_Log_Msg_Android_Logcat
+ *
+ * @brief Implements an ACE_Log_Msg_Backend that logs messages to Android's
+ * logging system, called Logcat. On Android this is the default output for ACE
+ * and the only convenient way of logging.
+ *
+ * Reference to the Logging part of Android's NDK API can be found here:
+ * https://developer.android.com/ndk/reference/group/logging
+ */
+class ACE_Export ACE_Log_Msg_Android_Logcat : public ACE_Log_Msg_Backend
+{
+public:
+ ACE_Log_Msg_Android_Logcat ();
+ virtual ~ACE_Log_Msg_Android_Logcat ();
+
+ /// Initialize the event logging facility. NOP in this class.
+ virtual int open (const ACE_TCHAR *);
+
+ /// Reset the backend. NOP in this class.
+ virtual int reset ();
+
+ /// Close the backend completely. NOP in this class.
+ virtual int close ();
+
+ /// This is called when we want to log a message.
+ virtual ssize_t log (ACE_Log_Record &log_record);
+};
+
+ACE_END_VERSIONED_NAMESPACE_DECL
+
+#endif
+
+#include /**/ "ace/post.h"
+#endif /* ACE_LOG_MSG_ANDROID_LOGCAT */
diff --git a/ACE/ace/ace.mpc b/ACE/ace/ace.mpc
index b0aa313dd17..dac0888baef 100644
--- a/ACE/ace/ace.mpc
+++ b/ACE/ace/ace.mpc
@@ -92,6 +92,7 @@ project(ACE) : ace_output, acedefaults, install, other, codecs, token, svcconf,
Lock.cpp
Log_Category.cpp
Log_Msg.cpp
+ Log_Msg_Android_Logcat.cpp
Log_Msg_Backend.cpp
Log_Msg_Callback.cpp
Log_Msg_IPC.cpp