From 635a94e141d3c0d73130069e979f4bb63d464c1d Mon Sep 17 00:00:00 2001 From: Saya Sugiura Date: Tue, 8 Dec 2020 10:22:42 +0900 Subject: logstorage: Implement general config to maintain logstorage loglevel Runtime log level setting from dlt-viewer or dlt-control doesn't work when logstorage is enabled. Adding MaintainLogstorageLogLevel=ON/OFF to [General] session of dlt_logstorage.conf to keep the current behaviour (=ON or 1 or not defined), or allow to change log level from dlt-viewer or dlt-control when the logstorage is enabled (=OFF or 0). Signed-off-by: KHANH LUONG HONG DUY Signed-off-by: Bui Nguyen Quoc Thanh --- include/dlt/dlt_types.h | 7 ++ src/daemon/dlt-daemon.c | 3 + src/daemon/dlt_daemon_client.c | 6 ++ src/daemon/dlt_daemon_common.c | 7 +- src/daemon/dlt_daemon_common.h | 1 + src/daemon/dlt_daemon_offline_logstorage.c | 10 ++ src/offlinelogstorage/dlt_offline_logstorage.c | 128 ++++++++++++++++++++++++- src/offlinelogstorage/dlt_offline_logstorage.h | 6 ++ 8 files changed, 163 insertions(+), 5 deletions(-) diff --git a/include/dlt/dlt_types.h b/include/dlt/dlt_types.h index 9943e31..2880c89 100644 --- a/include/dlt/dlt_types.h +++ b/include/dlt/dlt_types.h @@ -173,6 +173,13 @@ typedef enum DLT_USER_MODE_MAX /**< maximum value, used for range check */ } DltUserLogMode; +/** + * Definition of Maintain Logstorage Loglevel modes + */ +#define DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF -1 +#define DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF 0 +#define DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON 1 + typedef float float32_t; typedef double float64_t; diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 775d3a9..8e37c17 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -1239,6 +1239,9 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in dlt_get_version(daemon->ECUVersionString, DLT_DAEMON_TEXTBUFSIZE); } + /* Set to allows to maintain logstorage loglevel as default */ + daemon->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON; + return 0; } diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index 081f524..871ae30 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -2548,6 +2548,12 @@ void dlt_daemon_control_service_logstorage(int sock, DLT_SERVICE_RESPONSE_OK, verbose); + /* Update maintain logstorage loglevel if necessary */ + if (daemon->storage_handle[device_index].maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF) + { + daemon->maintain_logstorage_loglevel = daemon->storage_handle[device_index].maintain_logstorage_loglevel; + } + /* Check if log level of running application needs an update */ dlt_daemon_logstorage_update_application_loglevel(daemon, daemon_local, diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index cff1a9e..35ad9d6 100644 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -1354,9 +1354,10 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context, return -1; } - if (context->storage_log_level != DLT_LOG_DEFAULT) - usercontext.log_level = context->log_level > - context->storage_log_level ? context->log_level : context->storage_log_level; + if ((context->storage_log_level != DLT_LOG_DEFAULT) && + (daemon->maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF)) + usercontext.log_level = context->log_level > + context->storage_log_level ? context->log_level : context->storage_log_level; else /* Storage log level is not updated (is DEFAULT) then no device is yet connected so ignore */ usercontext.log_level = ((context->log_level == DLT_LOG_DEFAULT) ? daemon->default_log_level : context->log_level); diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h index 8586e1b..f650ce3 100644 --- a/src/daemon/dlt_daemon_common.h +++ b/src/daemon/dlt_daemon_common.h @@ -190,6 +190,7 @@ typedef struct char *ECUVersionString; /**< Version string to send to client. Loaded from a file at startup. May be null. */ DltDaemonState state; /**< the current logging state of dlt daemon. */ DltLogStorage *storage_handle; + int maintain_logstorage_loglevel; /* Permission to maintain the logstorage loglevel*/ } DltDaemon; /** diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c index dc06dc8..5d21a76 100644 --- a/src/daemon/dlt_daemon_offline_logstorage.c +++ b/src/daemon/dlt_daemon_offline_logstorage.c @@ -1095,6 +1095,16 @@ int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, 0, verbose); + if (daemon->storage_handle[0].maintain_logstorage_loglevel != + DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF) { + daemon->maintain_logstorage_loglevel = + daemon->storage_handle[0].maintain_logstorage_loglevel; + + dlt_vlog(LOG_DEBUG, "[%s] Startup with maintain loglevel: [%d]\n", + __func__, + daemon->storage_handle[0].maintain_logstorage_loglevel); + } + return ret; } diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c index 2bf5fad..07d09a5 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage.c +++ b/src/offlinelogstorage/dlt_offline_logstorage.c @@ -1503,6 +1503,126 @@ DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle, return ret; } +/** + * dlt_logstorage_check_maintain_logstorage_loglevel + * + * Evaluate to maintain the logstorage loglevel setting. This is an optional + * configuration parameter + * If the given value cannot be associated with an overwrite, the default value + * will be assigned. + * + * @param config DltLogStorage + * @param value string given in config file + * @return 0 on success, -1 on error + */ +DLT_STATIC int dlt_logstorage_check_maintain_logstorage_loglevel(DltLogStorage *handle, + char *value) +{ + if ((handle == NULL) || (value == NULL)) + { + return -1; + } + + if ((strncmp(value, "OFF", 3) == 0) || (strncmp(value, "0", 1) == 0)) + { + handle->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_OFF; + } + else if ((strncmp(value, "ON", 2) == 0) || (strncmp(value, "1", 1) == 0)) + { + handle->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON; + } + else + { + dlt_vlog(LOG_ERR, + "Wrong value for Maintain logstorage loglevel section name: %s\n", value); + handle->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_ON; + return -1; + } + + return 0; +} + +DLT_STATIC DltLogstorageGeneralConf + general_cfg_entries[DLT_LOGSTORAGE_GENERAL_CONF_COUNT] = { + [DLT_LOGSTORAGE_GENERAL_CONF_MAINTAIN_LOGSTORAGE_LOGLEVEL] = { + .key = "MaintainLogstorageLogLevel", + .func = dlt_logstorage_check_maintain_logstorage_loglevel, + .is_opt = 1 + } +}; + +/** + * Check if DltLogstorage General configuration parameter is valid. + * + * @param handle pointer to DltLogstorage structure + * @param ctype Logstorage general configuration type + * @param value specified property value from configuration file + * @return 0 on success, -1 otherwise + */ +DLT_STATIC int dlt_logstorage_check_general_param(DltLogStorage *handle, + DltLogstorageGeneralConfType ctype, + char *value) +{ + if ((handle == NULL) || (value == NULL)) + { + return -1; + } + + if (ctype < DLT_LOGSTORAGE_GENERAL_CONF_COUNT) + { + return general_cfg_entries[ctype].func(handle, value); + } + + return -1; +} + +DLT_STATIC int dlt_daemon_setup_general_properties(DltLogStorage *handle, + DltConfigFile *config_file, + char *sec_name) +{ + DltLogstorageGeneralConfType type = DLT_LOGSTORAGE_GENERAL_CONF_MAINTAIN_LOGSTORAGE_LOGLEVEL; + char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = {0}; + + if ((handle == NULL) || (config_file == NULL) || (sec_name == NULL)) + { + return -1; + } + + for ( ; type < DLT_LOGSTORAGE_GENERAL_CONF_COUNT ; type++) + { + if (dlt_config_file_get_value(config_file, + sec_name, + general_cfg_entries[type].key, + value) == 0) + { + if (dlt_logstorage_check_general_param(handle, type, value) != 0) + { + dlt_vlog(LOG_WARNING, + "General parameter %s [%s] is invalid\n", + general_cfg_entries[type].key, value); + } + } + else + { + if (general_cfg_entries[type].is_opt == 1) + { + dlt_vlog(LOG_DEBUG, + "Optional General parameter %s not given\n", + general_cfg_entries[type].key); + } + else + { + dlt_vlog(LOG_ERR, + "General parameter %s not given\n", + general_cfg_entries[type].key); + return -1; + } + } + } + + return 0; +} + /** * dlt_logstorage_store_filters * @@ -1537,6 +1657,7 @@ DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage *handle, return -1; } + handle->maintain_logstorage_loglevel = DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF; dlt_config_file_get_num_sections(config, &num_sec); for (sec = 0; sec < num_sec; sec++) { @@ -1549,8 +1670,11 @@ DLT_STATIC int dlt_logstorage_store_filters(DltLogStorage *handle, } if (strstr(sec_name, GENERAL_BASE_NAME) != NULL) { - dlt_log(LOG_CRIT, "General configuration not supported \n"); - continue; + if (dlt_daemon_setup_general_properties(handle, config, sec_name) == -1) + { + dlt_log(LOG_CRIT, "General configuration is invalid\n"); + continue; + } } else if (dlt_logstorage_validate_filter_name(sec_name) == 0) { diff --git a/src/offlinelogstorage/dlt_offline_logstorage.h b/src/offlinelogstorage/dlt_offline_logstorage.h index b4acbfa..16252bc 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage.h +++ b/src/offlinelogstorage/dlt_offline_logstorage.h @@ -217,6 +217,7 @@ typedef struct unsigned int config_status; /* Status of configuration */ int write_errors; /* number of write errors */ DltNewestFileName *newest_file_list; /* List of newest file name */ + int maintain_logstorage_loglevel; /* Permission to maintain the logstorage loglevel*/ } DltLogStorage; typedef struct { @@ -225,6 +226,11 @@ typedef struct { int is_opt; /* If configuration is optional or not */ } DltLogstorageGeneralConf; +typedef enum { + DLT_LOGSTORAGE_GENERAL_CONF_MAINTAIN_LOGSTORAGE_LOGLEVEL = 1, + DLT_LOGSTORAGE_GENERAL_CONF_COUNT +} DltLogstorageGeneralConfType; + typedef struct { char *key; /* Configuration key */ int (*func)(DltLogStorageFilterConfig *config, char *value); /* conf handler */ -- cgit v1.2.1