Add android logd logging support

Add log_dest android in order to forward logs into the Android logging
system (logd). Link liblog (included in each Android NDK) if building
for Android. Add configuration note about log_dest android to the
configuration template.

Signed-off-by: Felix Obenhuber <felix.obenhuber@esrlabs.com>
pull/2665/head
Felix Obenhuber 3 years ago
parent 59ec303372
commit 5437fb5aef

@ -524,6 +524,9 @@
# The dlt destination is for the automotive `Diagnostic Log and Trace` tool. # The dlt destination is for the automotive `Diagnostic Log and Trace` tool.
# This requires that Mosquitto has been compiled with DLT support. # This requires that Mosquitto has been compiled with DLT support.
# #
# The android destination is for logging into the Android logd logging daemon.
# This options is only available when building for the Android target.
#
# Note that if the broker is running as a Windows service it will default to # Note that if the broker is running as a Windows service it will default to
# "log_dest none" and neither stdout nor stderr logging is available. # "log_dest none" and neither stdout nor stderr logging is available.
# Use "log_dest none" if you wish to disable logging. # Use "log_dest none" if you wish to disable logging.

@ -195,6 +195,10 @@ if(WITH_WEBSOCKETS)
endif() endif()
endif() endif()
if (ANDROID)
set (MOSQ_LIBS ${MOSQ_LIBS} log)
endif (ANDROID)
add_executable(mosquitto ${MOSQ_SRCS}) add_executable(mosquitto ${MOSQ_SRCS})
if(WITH_WEBSOCKETS) if(WITH_WEBSOCKETS)

@ -1810,6 +1810,10 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload,
cr->log_dest |= MQTT3_LOG_TOPIC; cr->log_dest |= MQTT3_LOG_TOPIC;
}else if(!strcmp(token, "dlt")){ }else if(!strcmp(token, "dlt")){
cr->log_dest |= MQTT3_LOG_DLT; cr->log_dest |= MQTT3_LOG_DLT;
#ifdef ANDROID
}else if(!strcmp(token, "android")){
cr->log_dest |= MQTT3_LOG_ANDROID;
#endif
}else if(!strcmp(token, "file")){ }else if(!strcmp(token, "file")){
cr->log_dest |= MQTT3_LOG_FILE; cr->log_dest |= MQTT3_LOG_FILE;
if(config->log_fptr || config->log_file){ if(config->log_fptr || config->log_file){

@ -44,6 +44,11 @@ Contributors:
HANDLE syslog_h; HANDLE syslog_h;
#endif #endif
#ifdef ANDROID
#include <android/log.h>
static const char* LOG_TAG = "mosquitto";
#endif
static char log_fptr_buffer[BUFSIZ]; static char log_fptr_buffer[BUFSIZ];
/* Options for logging should be: /* Options for logging should be:
@ -187,6 +192,28 @@ DltLogLevelType get_dlt_level(unsigned int priority)
} }
#endif #endif
#ifdef ANDROID
android_LogPriority get_android_level(unsigned int priority)
{
switch (priority) {
case MOSQ_LOG_ERR:
return ANDROID_LOG_ERROR;
case MOSQ_LOG_WARNING:
return ANDROID_LOG_WARN;
case MOSQ_LOG_INFO:
return ANDROID_LOG_INFO;
case MOSQ_LOG_DEBUG:
return ANDROID_LOG_DEBUG;
case MOSQ_LOG_NOTICE:
case MOSQ_LOG_SUBSCRIBE:
case MOSQ_LOG_UNSUBSCRIBE:
return ANDROID_LOG_VERBOSE;
default:
return ANDROID_LOG_DEBUG;
}
}
#endif
static int log__vprintf(unsigned int priority, const char *fmt, va_list va) static int log__vprintf(unsigned int priority, const char *fmt, va_list va)
{ {
const char *topic; const char *topic;
@ -333,6 +360,11 @@ static int log__vprintf(unsigned int priority, const char *fmt, va_list va)
if(log_destinations & MQTT3_LOG_DLT && priority != MOSQ_LOG_INTERNAL){ if(log_destinations & MQTT3_LOG_DLT && priority != MOSQ_LOG_INTERNAL){
DLT_LOG_STRING(dltContext, get_dlt_level(priority), log_line); DLT_LOG_STRING(dltContext, get_dlt_level(priority), log_line);
} }
#endif
#ifdef ANDROID
if(log_destinations & MQTT3_LOG_ANDROID && priority != MOSQ_LOG_INTERNAL){
__android_log_write(get_android_level(priority), LOG_TAG, log_line);
}
#endif #endif
} }

@ -55,6 +55,9 @@ Contributors:
#define MQTT3_LOG_STDERR 0x08 #define MQTT3_LOG_STDERR 0x08
#define MQTT3_LOG_TOPIC 0x10 #define MQTT3_LOG_TOPIC 0x10
#define MQTT3_LOG_DLT 0x20 #define MQTT3_LOG_DLT 0x20
#ifdef ANDROID
#define MQTT3_LOG_ANDROID 0x40
#endif
#define MQTT3_LOG_ALL 0xFF #define MQTT3_LOG_ALL 0xFF
#define CMD_PORT_LIMIT 10 #define CMD_PORT_LIMIT 10

Loading…
Cancel
Save