diff options
author | Adam Mitz <mitza@objectcomputing.com> | 2019-02-28 11:56:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-28 11:56:12 -0800 |
commit | b2d46d73f76778b27ddd474a1320364b62257ba3 (patch) | |
tree | a810749188f1d80f1c9fa578b811e2af1aa978c6 /ACE/ace | |
parent | 9f499a1fc09aa4c0f0dc73ae8a85a993e7eade76 (diff) | |
parent | ed5565b97dfffe6178e27a1eaec1064b35721c01 (diff) | |
download | ATCD-b2d46d73f76778b27ddd474a1320364b62257ba3.tar.gz |
Merge pull request #834 from iguessthislldo/igtd/android
Use Logcat on Android
Diffstat (limited to 'ACE/ace')
-rw-r--r-- | ACE/ace/Log_Msg.cpp | 26 | ||||
-rw-r--r-- | ACE/ace/Log_Msg.h | 12 | ||||
-rw-r--r-- | ACE/ace/Log_Msg_Android_Logcat.cpp | 81 | ||||
-rw-r--r-- | ACE/ace/Log_Msg_Android_Logcat.h | 59 | ||||
-rw-r--r-- | ACE/ace/ace.mpc | 1 |
5 files changed, 169 insertions, 10 deletions
diff --git a/ACE/ace/Log_Msg.cpp b/ACE/ace/Log_Msg.cpp index 535d567d0a5..190c6d7815d 100644 --- a/ACE/ace/Log_Msg.cpp +++ b/ACE/ace/Log_Msg.cpp @@ -47,7 +47,9 @@ #include "ace/Log_Msg.inl" #endif /* __ACE_INLINE__ */ - +#ifdef ACE_ANDROID +# include "ace/Log_Msg_Android_Logcat.h" +#endif ACE_BEGIN_VERSIONED_NAMESPACE_DECL @@ -80,11 +82,11 @@ 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) +# 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 @@ -136,7 +138,15 @@ private: ACE_Log_Msg_Backend *ACE_Log_Msg_Manager::log_backend_ = 0; ACE_Log_Msg_Backend *ACE_Log_Msg_Manager::custom_backend_ = 0; -u_long ACE_Log_Msg_Manager::log_backend_flags_ = 0; +#ifndef ACE_DEFAULT_LOG_BACKEND_FLAGS +# ifdef ACE_ANDROID +# define ACE_DEFAULT_LOG_BACKEND_FLAGS ACE_Log_Msg::SYSLOG +# else +# define ACE_DEFAULT_LOG_BACKEND_FLAGS 0 +# endif +#endif + +u_long ACE_Log_Msg_Manager::log_backend_flags_ = ACE_DEFAULT_LOG_BACKEND_FLAGS; int ACE_Log_Msg_Manager::init_backend (const u_long *flags) { @@ -166,14 +176,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); @@ -425,7 +435,7 @@ const ACE_TCHAR *ACE_Log_Msg::local_host_ = 0; const ACE_TCHAR *ACE_Log_Msg::program_name_ = 0; /// Default is to use stderr. -u_long ACE_Log_Msg::flags_ = ACE_Log_Msg::STDERR; +u_long ACE_Log_Msg::flags_ = ACE_DEFAULT_LOG_FLAGS; /// Current offset of msg_[]. ptrdiff_t ACE_Log_Msg::msg_off_ = 0; diff --git a/ACE/ace/Log_Msg.h b/ACE/ace/Log_Msg.h index 2aac2fe0167..92c54cecbca 100644 --- a/ACE/ace/Log_Msg.h +++ b/ACE/ace/Log_Msg.h @@ -161,6 +161,14 @@ # undef THREAD #endif /* THREAD */ +#ifndef ACE_DEFAULT_LOG_FLAGS +# ifdef ACE_ANDROID +# define ACE_DEFAULT_LOG_FLAGS ACE_Log_Msg::STDERR | ACE_Log_Msg::SYSLOG +# else +# define ACE_DEFAULT_LOG_FLAGS ACE_Log_Msg::STDERR +# endif +#endif + ACE_BEGIN_VERSIONED_NAMESPACE_DECL class ACE_Log_Msg_Callback; @@ -234,7 +242,7 @@ public: SYSLOG = 128, /// Write messages to the user provided backend CUSTOM = 256 - }; + }; // = Initialization and termination routines. @@ -284,7 +292,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 |