diff options
Diffstat (limited to 'include/dlt')
-rw-r--r-- | include/dlt/dlt_types.h | 1 | ||||
-rw-r--r-- | include/dlt/dlt_user.h | 23 | ||||
-rw-r--r-- | include/dlt/dlt_user_macros.h | 25 |
3 files changed, 41 insertions, 8 deletions
diff --git a/include/dlt/dlt_types.h b/include/dlt/dlt_types.h index cd12e77..03cd036 100644 --- a/include/dlt/dlt_types.h +++ b/include/dlt/dlt_types.h @@ -85,6 +85,7 @@ typedef unsigned int speed_t; */ typedef enum { + DLT_RETURN_LOGGING_DISABLED = -7, DLT_RETURN_USER_BUFFER_FULL = -6, DLT_RETURN_WRONG_PARAMETER = -5, DLT_RETURN_BUFFER_FULL = -4, diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index a24117e..792ebbe 100644 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -769,6 +769,29 @@ int dlt_user_atexit_blow_out_user_buffer(void); */ DltReturnValue dlt_user_log_resend_buffer(void); +/** + * Checks the log level passed by the log function if enabled for that context or not. + * This function can be called by applications before generating their logs. + * Also called before writing new log messages. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @return Value from DltReturnValue enum, DLT_RETURN_TRUE if log level is enabled + */ +static inline DltReturnValue dlt_user_is_logLevel_enabled(DltContext *handle,DltLogLevelType loglevel) +{ + if (handle == NULL || handle->log_level_ptr == NULL) + { + return DLT_RETURN_WRONG_PARAMETER; + } + + if (loglevel <= (DltLogLevelType)(*(handle->log_level_ptr)) && loglevel != DLT_LOG_OFF) + { + return DLT_RETURN_TRUE; + } + + return DLT_RETURN_LOGGING_DISABLED; +} + #ifdef DLT_TEST_ENABLE void dlt_user_test_corrupt_user_header(int enable); void dlt_user_test_corrupt_message_size(int enable,int16_t size); diff --git a/include/dlt/dlt_user_macros.h b/include/dlt/dlt_user_macros.h index 919df7e..e1e9104 100644 --- a/include/dlt/dlt_user_macros.h +++ b/include/dlt/dlt_user_macros.h @@ -181,7 +181,7 @@ #else #define DLT_LOG(CONTEXT,LOGLEVEL,ARGS...) \ do { \ - if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \ + if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \ { \ DltContextData log_local; \ int dlt_local; \ @@ -213,7 +213,7 @@ #else #define DLT_LOG_ID(CONTEXT,LOGLEVEL,MSGID,ARGS...) \ do { \ - if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \ + if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \ { \ DltContextData log_local; \ int dlt_local; \ @@ -398,7 +398,7 @@ */ #define DLT_LOG_STRING(CONTEXT,LOGLEVEL,TEXT) \ do { \ - if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \ + if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \ { \ (void)dlt_log_string(&(CONTEXT), LOGLEVEL, TEXT); \ } \ @@ -413,7 +413,7 @@ */ #define DLT_LOG_STRING_INT(CONTEXT,LOGLEVEL,TEXT,INT_VAR) \ do { \ - if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \ + if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \ { \ (void)dlt_log_string_int(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \ } \ @@ -428,7 +428,7 @@ */ #define DLT_LOG_STRING_UINT(CONTEXT,LOGLEVEL,TEXT,UINT_VAR) \ do { \ - if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \ + if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \ { \ (void)dlt_log_string_uint(&(CONTEXT),LOGLEVEL,TEXT,UINT_VAR); \ } \ @@ -442,7 +442,7 @@ */ #define DLT_LOG_UINT(CONTEXT,LOGLEVEL,UINT_VAR) \ do { \ - if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \ + if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \ { \ (void)dlt_log_uint(&(CONTEXT),LOGLEVEL,UINT_VAR); \ } \ @@ -456,7 +456,7 @@ */ #define DLT_LOG_INT(CONTEXT,LOGLEVEL,INT_VAR) \ do { \ - if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \ + if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \ { \ (void)dlt_log_int(&(CONTEXT),LOGLEVEL,INT_VAR); \ } \ @@ -471,7 +471,7 @@ */ #define DLT_LOG_RAW(CONTEXT,LOGLEVEL,BUF,LEN) \ do { \ - if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \ + if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \ { \ (void)dlt_log_raw(&(CONTEXT),LOGLEVEL,BUF,LEN); \ } \ @@ -523,6 +523,15 @@ (void)dlt_disable_local_print();} while(0) /** + * Check if log level is enabled + * + * @param CONTEXT object containing information about one special logging context + * @param LOGLEVEL the log level of the log message + */ +#define DLT_IS_LOG_LEVEL_ENABLED(CONTEXT,LOGLEVEL) \ + (dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL) == DLT_RETURN_TRUE) + +/** \} */ |