From c3b53f8805236cb7c72eb62ef04866f34de33103 Mon Sep 17 00:00:00 2001 From: Stefan Vacek Date: Wed, 26 Aug 2015 17:28:54 +0200 Subject: Add env-var to set initial log-levels name of environment variable: DLT_INITIAL_LOG_LEVEL Syntax: ::;::;... apid: application id (up to 4 chars), if empty all applications will match ctid: context id (up to 4 chars), if empty all contexts will match loglevel: either -1..6 or a symbolic name (default, off, fatal, error, warning, info, debug, verbose) Examples: DLT_INITIAL_LOG_LEVEL=TEST:LOG:0 -> turn off logging for appid TEST and contextid LOG DLT_INITIAL_LOG_LEVEL=:LOG:warn -> for contexts with name "LOG" set log-level to warning (3) DLT_INITIAL_LOG_LEVEL=::VERBOSE -> set log-level of all contexts to VERBOSE DLT_INITIAL_LOG_LEVEL=::VERBOSE;TEST:LOG:3 -> set log-level of all contexts to VERBOSE except TEST:LOG, set this to WARNING dlt-example-user: add option -l to specify log-level to be used when sending messages Signed-off-by: Stefan Vacek --- include/dlt/dlt_user.h | 74 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index 66a869b..baa5746 100644 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -176,11 +176,11 @@ typedef enum */ typedef struct { - char contextID[4]; /**< context id */ - int32_t log_level_pos; /**< offset in user-application context field */ - int8_t *log_level_ptr; /**< pointer to the log level */ - int8_t *trace_status_ptr; /**< pointer to the trace status */ - uint8_t mcnt; /**< message counter */ + char contextID[DLT_ID_SIZE]; /**< context id */ + int32_t log_level_pos; /**< offset in user-application context field */ + int8_t *log_level_ptr; /**< pointer to the log level */ + int8_t *trace_status_ptr; /**< pointer to the trace status */ + uint8_t mcnt; /**< message counter */ } DltContext; /** @@ -230,6 +230,28 @@ typedef struct } dlt_ll_ts_type; +/** + * @brief holds initial log-level for given appId:ctxId pair + */ +typedef struct +{ + char appId[DLT_ID_SIZE]; + char ctxId[DLT_ID_SIZE]; + int8_t ll; +} dlt_env_ll_item; + + +/** + * @brief holds all initial log-levels given via environment variable DLT_INITIAL_LOG_LEVEL + */ +typedef struct +{ + dlt_env_ll_item * item; + size_t array_size; + size_t num_elem; +} dlt_env_ll_set; + + /** * This structure is used once for one application. */ @@ -278,6 +300,8 @@ typedef struct // Buffer used for resending, locked by DLT semaphore uint8_t resend_buffer[DLT_USER_RESENDBUF_MAX_SIZE]; + dlt_env_ll_set initial_ll_set; + #ifdef DLT_SHM_ENABLE DltShm dlt_shm; #endif @@ -491,7 +515,7 @@ int dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType nw_ int dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload); /************************************************************************************************** - * The folowing API functions define a high level function interface for DLT + * The following API functions define a high level function interface for DLT **************************************************************************************************/ /** @@ -556,9 +580,9 @@ int dlt_register_context(DltContext *handle, const char *contextid, const char * * @param contextid four byte long character array with the context id * @param description long name of the context * @param loglevel This is the log level to be pre-set for this context - (DLT_LOG_DEFAULT is not allowed here) + (DLT_LOG_DEFAULT is not allowed here) * @param tracestatus This is the trace status to be pre-set for this context - (DLT_TRACE_STATUS_DEFAULT is not allowed here) + (DLT_TRACE_STATUS_DEFAULT is not allowed here) * @return negative value if there was an error */ int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const char * description, int loglevel, int tracestatus); @@ -670,6 +694,40 @@ int dlt_with_ecu_id(int8_t with_ecu_id); */ int dlt_set_application_ll_ts_limit(DltLogLevelType loglevel, DltTraceStatusType tracestatus); + +/** + * @brief adjust log-level based on values given through environment + * + * Iterate over the set of items, and find the best match. + * For any item that matches, the one with the highest priority is selected and that + * log-level is returned. + * + * Priorities are determined as follows: + * - no apid, no ctid only ll given in item: use ll with prio 1 + * - no apid, ctid matches: use ll with prio 2 + * - no ctid, apid matches: use ll with prio 3 + * - apid, ctid matches: use ll with prio 4 + * + * If no item matches or in case of error, the original log-level (\param ll) is returned + */ +int dlt_env_adjust_ll_from_env(dlt_env_ll_set const * const ll_set, char const * const apid, char const * const ctid, int const ll); + +/** + * @brief extract log-level settings from given string + * + * Scan \param env for setttings like apid:ctid:log-level and store them + * in given \param ll_set + * + * @param env reference to a string to be parsed, after parsing env will point after the last parse character + * @param ll_set set of log-level extracted from given string + * + * @return 0 on success + * @return -1 on failure + */ +int dlt_env_extract_ll_set(char ** const env, dlt_env_ll_set * const ll_set); + +void dlt_env_free_ll_set(dlt_env_ll_set * const ll_set); + /** * Enable local printing of messages * -- cgit v1.2.1