Skip to content

Commit

Permalink
Merge pull request #834 from iguessthislldo/igtd/android
Browse files Browse the repository at this point in the history
Use Logcat on Android
  • Loading branch information
mitza-oci authored Feb 28, 2019
2 parents 9f499a1 + ed5565b commit b2d46d7
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 10 deletions.
9 changes: 9 additions & 0 deletions ACE/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
====================================================

Expand Down
26 changes: 18 additions & 8 deletions ACE/ace/Log_Msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -80,11 +82,11 @@ class ACE_Msg_Log_Cleanup: public ACE_Cleanup_Adapter<ACE_Log_Msg>

#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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions ACE/ace/Log_Msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down
81 changes: 81 additions & 0 deletions ACE/ace/Log_Msg_Android_Logcat.cpp
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions ACE/ace/Log_Msg_Android_Logcat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @file Log_Msg_Android_Logcat.h
*
* @author Frederick Hornsey <[email protected]>
*/

#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 */
1 change: 1 addition & 0 deletions ACE/ace/ace.mpc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions ACE/include/makeinclude/platform_android.GNU
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,6 @@ ifeq ($(threads),1)
PRELIB = @true
endif # ! PRELIB
endif

# Link To Android Logging Library for Log_Msg_Android_Logcat
LIBS += -llog

0 comments on commit b2d46d7

Please sign in to comment.