diff --git a/ACE/NEWS b/ACE/NEWS index 1148ba820675f..fd9c670b35e9f 100644 --- a/ACE/NEWS +++ b/ACE/NEWS @@ -4,6 +4,15 @@ USER VISIBLE CHANGES BETWEEN ACE-6.5.4 and ACE-6.5.5 . Fixed several broken links due to the removal of Douglas Schmidt website at WashU +. On Android, ACE_Log_Msg (and therefore ACE_DEBUG and ACE_ERROR) now uses + Android's logging system (aka Logcat) by default in addition to stderr + because stdout and stderr are discarded under normal circumstances. + To disable this at runtime, run: + ACE_LOG_MSG->clr_flags (ACE_Log_Msg::SYSLOG) + To disable this at compile time include these lines in config.h: + #define ACE_DEFAULT_LOG_FLAGS ACE_Log_Msg::STDERR + #define ACE_DEFAULT_LOG_BACKEND_FLAGS 0 + USER VISIBLE CHANGES BETWEEN ACE-6.5.3 and ACE-6.5.4 ==================================================== diff --git a/ACE/ace/Log_Msg.cpp b/ACE/ace/Log_Msg.cpp index 535d567d0a5fa..190c6d7815d4a 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 @@ class ACE_Msg_Log_Cleanup: public ACE_Cleanup_Adapter #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 @@ class ACE_Log_Msg_Manager 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 2aac2fe0167e1..92c54cecbcaab 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 @@ class ACE_Export ACE_Log_Msg SYSLOG = 128, /// Write messages to the user provided backend CUSTOM = 256 - }; + }; // = Initialization and termination routines. @@ -284,7 +292,7 @@ class ACE_Export ACE_Log_Msg * @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 0000000000000..8fc517be09950 --- /dev/null +++ b/ACE/ace/Log_Msg_Android_Logcat.cpp @@ -0,0 +1,81 @@ +#include "ace/config-all.h" + +#ifdef ACE_ANDROID + +#include // 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 (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 0000000000000..8eb9c2662725a --- /dev/null +++ b/ACE/ace/Log_Msg_Android_Logcat.h @@ -0,0 +1,59 @@ +/** + * @file Log_Msg_Android_Logcat.h + * + * @author Frederick Hornsey + */ + +#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 b0aa313dd17c6..dac0888baef7b 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 diff --git a/ACE/include/makeinclude/platform_android.GNU b/ACE/include/makeinclude/platform_android.GNU index 597360bd20e9c..b3d77eb92c9e4 100644 --- a/ACE/include/makeinclude/platform_android.GNU +++ b/ACE/include/makeinclude/platform_android.GNU @@ -174,3 +174,6 @@ ifeq ($(threads),1) PRELIB = @true endif # ! PRELIB endif + +# Link To Android Logging Library for Log_Msg_Android_Logcat +LIBS += -llog