Implement DLT logging feature for automotive platform

Signed-off-by: JaeHoon Lee <bbabbi01@gmail.com>
This commit is contained in:
JaeHoon Lee 2018-10-21 14:34:03 +00:00
parent 07d59d20e2
commit 2cb0354163
3 changed files with 55 additions and 1 deletions

View File

@ -75,6 +75,14 @@ option(WITH_SRV "Include SRV lookup support?" OFF)
option(DOCUMENTATION "Build documentation?" ON)
option(WITH_DLT "Include DLT support (requires WITH_DLT)?" OFF)
message(STATUS "WITH_DLT = ${WITH_DLT}")
if (${WITH_DLT} STREQUAL ON)
#find_package(DLT REQUIRED)
find_package(PkgConfig)
pkg_check_modules(DLT "automotive-dlt >= 2.11")
add_definitions("-DWITH_DLT")
endif (${WITH_DLT} STREQUAL ON)
# ========================================
# Include projects
# ========================================

View File

@ -115,8 +115,13 @@ endif (WIN32 OR CYGWIN)
add_definitions (-DWITH_BROKER)
set (MOSQ_LIBS ${MOSQ_LIBS} ${OPENSSL_LIBRARIES})
if (${WITH_DLT} STREQUAL ON)
message(STATUS "DLT_LIBDIR = ${DLT_LIBDIR}")
link_directories(${DLT_LIBDIR})
set (MOSQ_LIBS ${DLT_LIBRARIES})
endif (${WITH_DLT} STREQUAL ON)
set (MOSQ_LIBS ${MOSQ_LIBS} ${OPENSSL_LIBRARIES})
# Check for getaddrinfo_a
include(CheckLibraryExists)
check_library_exists(anl getaddrinfo_a "" HAVE_GETADDRINFO_A)

View File

@ -23,6 +23,10 @@ Contributors:
#endif
#include <time.h>
#ifdef WITH_DLT
#include <dlt/dlt.h>
#endif
#include "mosquitto_broker_internal.h"
#include "memory_mosq.h"
#include "util_mosq.h"
@ -48,6 +52,10 @@ HANDLE syslog_h;
static int log_destinations = MQTT3_LOG_STDERR;
static int log_priorities = MOSQ_LOG_ERR | MOSQ_LOG_WARNING | MOSQ_LOG_NOTICE | MOSQ_LOG_INFO;
#ifdef WITH_DLT
static DltContext dltContext;
#endif
int log__init(struct mosquitto__config *config)
{
int rc = 0;
@ -76,6 +84,10 @@ int log__init(struct mosquitto__config *config)
}
restore_privileges();
}
#ifdef WITH_DLT
DLT_REGISTER_APP("MQTT","mosquitto log");
dlt_register_context(&dltContext, "MQTT", "mosquitto DLT context");
#endif
return rc;
}
@ -95,10 +107,36 @@ int log__close(struct mosquitto__config *config)
}
}
#ifdef WITH_DLT
dlt_unregister_context(&dltContext);
DLT_UNREGISTER_APP();
#endif
/* FIXME - do something for all destinations! */
return MOSQ_ERR_SUCCESS;
}
#ifdef WITH_DLT
DltLogLevelType get_dlt_level(int priority)
{
switch (priority) {
case MOSQ_LOG_ERR:
return DLT_LOG_ERROR;
case MOSQ_LOG_WARNING:
return DLT_LOG_WARN;
case MOSQ_LOG_INFO:
return DLT_LOG_INFO;
case MOSQ_LOG_DEBUG:
return DLT_LOG_DEBUG;
case MOSQ_LOG_NOTICE:
case MOSQ_LOG_SUBSCRIBE:
case MOSQ_LOG_UNSUBSCRIBE:
return DLT_LOG_VERBOSE;
default:
return DLT_LOG_DEFAULT;
}
}
#endif
int log__vprintf(int priority, const char *fmt, va_list va)
{
char *s;
@ -245,6 +283,9 @@ int log__vprintf(int priority, const char *fmt, va_list va)
db__messages_easy_queue(&int_db, NULL, topic, 2, strlen(s), s, 0);
}
}
#ifdef WITH_DLT
DLT_LOG_STRING(dltContext, get_dlt_level(priority), s);
#endif
mosquitto__free(s);
}