summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSebastian Unger <sunger@de.adit-jv.com>2019-06-13 13:41:12 +0200
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2019-09-13 08:48:03 +0900
commitecca21fd40be21164d664eb7d8a52ea1fdabfde0 (patch)
treefe63a7805235da22b67ff7f39d45f09af813db2e /include
parent14ea971be7e808b9c5099c7f404ed3cf341873c4 (diff)
downloadDLT-daemon-ecca21fd40be21164d664eb7d8a52ea1fdabfde0.tar.gz
Add user custom timestamp interface
Two new macros are introduced so that users can use their customized timestamps for DLT messages: - DLT_LOG_TS(CONTEXT, LOGLEVEL, TS, ARGS ...) - DLT_LOG_ID_TS(CONTEXT, LOGLEVEL, MSGID, TS, ARGS ...) Detailed explanations can be found in dlt_for_developers.md. Also a new option is added to dlt-system to use events' timestamps from journald adapter. Signed-off-by: Sebastian Unger <sunger@de.adit-jv.com>
Diffstat (limited to 'include')
-rw-r--r--include/dlt/dlt_types.h9
-rw-r--r--include/dlt/dlt_user.h2
-rw-r--r--include/dlt/dlt_user_macros.h62
3 files changed, 73 insertions, 0 deletions
diff --git a/include/dlt/dlt_types.h b/include/dlt/dlt_types.h
index f63d046..0047233 100644
--- a/include/dlt/dlt_types.h
+++ b/include/dlt/dlt_types.h
@@ -188,4 +188,13 @@ typedef enum
} DltUserConnectionState;
#endif
+/**
+ * Definition of timestamp types
+ */
+typedef enum
+{
+ DLT_AUTO_TIMESTAMP = 0,
+ DLT_USER_TIMESTAMP
+} DltTimestampType;
+
#endif /* DLT_TYPES_H */
diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h
index 0804f7e..405d342 100644
--- a/include/dlt/dlt_user.h
+++ b/include/dlt/dlt_user.h
@@ -122,6 +122,8 @@ typedef struct
int32_t trace_status; /**< trace status */
int32_t args_num; /**< number of arguments for extended header*/
char *context_description; /**< description of context */
+ DltTimestampType use_timestamp; /**< whether to use user-supplied timestamps */
+ uint32_t user_timestamp; /**< user-supplied timestamp to use */
} DltContextData;
typedef struct
diff --git a/include/dlt/dlt_user_macros.h b/include/dlt/dlt_user_macros.h
index df9f375..4ad6854 100644
--- a/include/dlt/dlt_user_macros.h
+++ b/include/dlt/dlt_user_macros.h
@@ -69,6 +69,7 @@
#define DLT_USER_MACROS_H
#include "dlt_version.h"
+#include "dlt_types.h"
/**
* \defgroup userapi DLT User API
@@ -217,6 +218,35 @@
#endif
/**
+ * Send log message with variable list of messages (intended for verbose mode)
+ * @param CONTEXT object containing information about one special logging context
+ * @param LOGLEVEL the log level of the log message
+ * @param TS timestamp to be used for log message
+ * @param ARGS variable list of arguments
+ * @note To avoid the MISRA warning "The comma operator has been used outside a for statement"
+ * use a semicolon instead of a comma to separate the ARGS.
+ * Example: DLT_LOG_TS(hContext, DLT_LOG_INFO, timestamp, DLT_STRING("Hello world"); DLT_INT(123));
+ */
+#ifdef _MSC_VER
+/* DLT_LOG_TS is not supported by MS Visual C++ */
+/* use function interface instead */
+#else
+# define DLT_LOG_TS(CONTEXT, LOGLEVEL, TS, ARGS ...) \
+ do { \
+ DltContextData log_local; \
+ int dlt_local; \
+ dlt_local = dlt_user_log_write_start(&CONTEXT, &log_local, LOGLEVEL); \
+ if (dlt_local == DLT_RETURN_TRUE) \
+ { \
+ ARGS; \
+ log_local.use_timestamp = DLT_USER_TIMESTAMP; \
+ log_local.user_timestamp = (uint32_t) TS; \
+ (void)dlt_user_log_write_finish(&log_local); \
+ } \
+ } while (0)
+#endif
+
+/**
* Send log message with variable list of messages (intended for non-verbose mode)
* @param CONTEXT object containing information about one special logging context
* @param LOGLEVEL the log level of the log message
@@ -246,6 +276,38 @@
#endif
/**
+ * Send log message with variable list of messages (intended for non-verbose mode)
+ * @param CONTEXT object containing information about one special logging context
+ * @param LOGLEVEL the log level of the log message
+ * @param MSGID the message id of log message
+ * @param TS timestamp to be used for log message
+ * @param ARGS variable list of arguments:
+ * calls to DLT_STRING(), DLT_BOOL(), DLT_FLOAT32(), DLT_FLOAT64(),
+ * DLT_INT(), DLT_UINT(), DLT_RAW()
+ * @note To avoid the MISRA warning "The comma operator has been used outside a for statement"
+ * use a semicolon instead of a comma to separate the ARGS.
+ * Example: DLT_LOG_ID_TS(hContext, DLT_LOG_INFO, 0x1234, timestamp, DLT_STRING("Hello world"); DLT_INT(123));
+ */
+#ifdef _MSC_VER
+/* DLT_LOG_ID_TS is not supported by MS Visual C++ */
+/* use function interface instead */
+#else
+# define DLT_LOG_ID_TS(CONTEXT, LOGLEVEL, MSGID, TS, ARGS ...) \
+ do { \
+ DltContextData log_local; \
+ int dlt_local; \
+ dlt_local = dlt_user_log_write_start_id(&CONTEXT, &log_local, LOGLEVEL, MSGID); \
+ if (dlt_local == DLT_RETURN_TRUE) \
+ { \
+ ARGS; \
+ log_local.use_timestamp = DLT_USER_TIMESTAMP; \
+ log_local.user_timestamp = (uint32_t) TS; \
+ (void)dlt_user_log_write_finish(&log_local); \
+ } \
+ } while (0)
+#endif
+
+/**
* Add string parameter to the log messsage.
* @param TEXT ASCII string
*/