mirror of
https://github.com/eclipse/mosquitto.git
synced 2025-05-09 01:01:11 +08:00
Merge pull request #993 from bbabbi01/origin/develop
Implement DLT logging
This commit is contained in:
commit
bb6da93e93
@ -99,6 +99,14 @@ endif (WITH_THREADING)
|
||||
|
||||
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
|
||||
# ========================================
|
||||
|
@ -120,8 +120,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)
|
||||
|
@ -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, 20, NULL);
|
||||
}
|
||||
}
|
||||
#ifdef WITH_DLT
|
||||
DLT_LOG_STRING(dltContext, get_dlt_level(priority), s);
|
||||
#endif
|
||||
mosquitto__free(s);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user