From 75f6c950b96aabaf6c76b35ac889b79cdbb1ff7f Mon Sep 17 00:00:00 2001 From: Daniel Weber <37300320+danielweber2018@users.noreply.github.com> Date: Wed, 15 May 2024 11:03:24 +0200 Subject: [PATCH] dlt-system: add config to use uptime only (#630) Add a new JournalUseUptimeOnly config toggle. With this toggle you can supress date and time from the dlt-system payload, so we show only the uptime of the system. This toggle is for data protection purposes. --- doc/dlt-system.conf.5.md | 11 ++++++++++ src/system/dlt-system-journal.c | 36 ++++++++++++++++++++++----------- src/system/dlt-system-options.c | 4 ++++ src/system/dlt-system.conf | 3 +++ src/system/dlt-system.h | 1 + 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/doc/dlt-system.conf.5.md b/doc/dlt-system.conf.5.md index b865b316c..e104e8c75 100644 --- a/doc/dlt-system.conf.5.md +++ b/doc/dlt-system.conf.5.md @@ -93,6 +93,17 @@ Map journal log levels to DLT log levels. Default: 1 +## JournalUseOriginalTimestamp + +Use the original timestamp (uptime when the event actually occured) as DLT timestamp. + + Default: 1 + +## JournalUseUptimeOnly + +Ignore the timestamp, show uptime (when the event actually occured) only in payload. + + Default: 0 # FILETRANSFER OPTIONS diff --git a/src/system/dlt-system-journal.c b/src/system/dlt-system-journal.c index 9d6380173..366555b61 100644 --- a/src/system/dlt-system-journal.c +++ b/src/system/dlt-system-journal.c @@ -286,28 +286,40 @@ void get_journal_msg(sd_journal *j, DltSystemConfiguration *config) else snprintf(buffer_priority, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "prio_unknown:"); - /* write log entry */ - if (config->Journal.UseOriginalTimestamp == 0) { + if (config->Journal.UseUptimeOnly == 1) { + /* write log entry (uptime only, no timestamp) */ DLT_LOG(journalContext, loglevel, - DLT_STRING(timestamp.real), - DLT_STRING(timestamp.monotonic), - DLT_STRING(buffer_process), - DLT_STRING(buffer_priority), - DLT_STRING(buffer_message) - ); - + DLT_STRING(timestamp.monotonic), + DLT_STRING(buffer_process), + DLT_STRING(buffer_priority), + DLT_STRING(buffer_message) + ); } else { - /* since we are talking about points in time, I'd prefer truncating over arithmetic rounding */ - ts = (uint32_t)(atof(timestamp.monotonic) * 10000); - DLT_LOG_TS(journalContext, loglevel, ts, + /* write log entry (including timestamp) */ + if (config->Journal.UseOriginalTimestamp == 0) { + DLT_LOG(journalContext, loglevel, DLT_STRING(timestamp.real), + DLT_STRING(timestamp.monotonic), DLT_STRING(buffer_process), DLT_STRING(buffer_priority), DLT_STRING(buffer_message) ); + + } + else { + /* since we are talking about points in time, I'd prefer truncating over arithmetic rounding */ + ts = (uint32_t)(atof(timestamp.monotonic) * 10000); + DLT_LOG_TS(journalContext, loglevel, ts, + DLT_STRING(timestamp.real), + DLT_STRING(buffer_process), + DLT_STRING(buffer_priority), + DLT_STRING(buffer_message) + ); + } } + if (journal_checkUserBufferForFreeSpace() == -1) { /* buffer is nearly full */ /* wait 500ms for writing next entry */ diff --git a/src/system/dlt-system-options.c b/src/system/dlt-system-options.c index d8b099bae..406f4cd4e 100644 --- a/src/system/dlt-system-options.c +++ b/src/system/dlt-system-options.c @@ -289,6 +289,10 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) { config->Journal.UseOriginalTimestamp = atoi(value); } + else if (strcmp(token, "JournalUseUptimeOnly") == 0) + { + config->Journal.UseUptimeOnly = atoi(value); + } /* File transfer */ else if (strcmp(token, "FiletransferEnable") == 0) diff --git a/src/system/dlt-system.conf b/src/system/dlt-system.conf index 77bc73e75..2816daadd 100644 --- a/src/system/dlt-system.conf +++ b/src/system/dlt-system.conf @@ -77,6 +77,9 @@ JournalMapLogLevels = 1 # Use the original timestamp (uptime when the event actually occured) as DLT timestamp (Default: 1) JournalUseOriginalTimestamp = 1 +# Ignore the timestamp, show uptime (when the event actually occured) only in payload (Default: 0) +JournalUseUptimeOnly = 0 + ######################################################################## # Filetransfer Manager ######################################################################## diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h index f39041323..a94b950ca 100644 --- a/src/system/dlt-system.h +++ b/src/system/dlt-system.h @@ -126,6 +126,7 @@ typedef struct { int Follow; int MapLogLevels; int UseOriginalTimestamp; + int UseUptimeOnly; #ifdef DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE_DLT_SYSTEM int MessageReceived; #endif