From 447ec05ffbd847052fe779f5a93e00ce9b52fd8c Mon Sep 17 00:00:00 2001 From: Lukas Woodtli Date: Fri, 24 May 2024 20:36:03 +0200 Subject: [PATCH] logging: Make logging handler declaration public The logging handler function can be customized. Therefore it belongs into to puplic header of Wakaama. --- core/internals.h | 25 ------------------------- include/liblwm2m.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/core/internals.h b/core/internals.h index a6679538..ef9e085e 100644 --- a/core/internals.h +++ b/core/internals.h @@ -64,17 +64,6 @@ #include "er-coap-13/er-coap-13.h" -#define LWM2M_DBG (10) -#define LWM2M_INFO (20) -#define LWM2M_WARN (30) -#define LWM2M_ERR (40) -#define LWM2M_FATAL (50) -#define LWM2M_LOG_DISABLED (0xff) - -#ifndef LWM2M_LOG_LEVEL -#define LWM2M_LOG_LEVEL LWM2M_LOG_DISABLED -#endif - #if LWM2M_LOG_LEVEL != LWM2M_LOG_DISABLED #include @@ -88,14 +77,6 @@ #define LWM2M_LOG_MAX_MSG_TXT_SIZE 200 #endif -typedef enum { - LWM2M_LOGGING_DBG = (uint8_t)LWM2M_DBG, - LWM2M_LOGGING_INFO = (uint8_t)LWM2M_INFO, - LWM2M_LOGGING_WARN = (uint8_t)LWM2M_WARN, - LWM2M_LOGGING_ERR = (uint8_t)LWM2M_ERR, - LWM2M_LOGGING_FATAL = (uint8_t)LWM2M_FATAL -} lwm2m_logging_level_t; - /* clang-format off */ #define STR_LOGGING_LEVEL(level) \ ((level) == LWM2M_LOGGING_DBG ? "DBG" : \ @@ -110,12 +91,6 @@ typedef enum { * This function should not be called directly. It's used internally in the logging system. */ char *lwm2m_log_fmt_message(const char *fmt, ...); -/** The default log handler for an log entry. To define a custom log handler define `LWM2M_LOG_CUSTOM_HANDLER` and - * implement a function with this signature. - * This function should not be called directly. Use the logging macros instead. */ -void lwm2m_log_handler(lwm2m_logging_level_t level, const char *const msg, const char *const func, const int line, - const char *const file); - /** Basic logging macro. Usually this is not called directly. Use the macros for a given level (e.g. LOG_DBG). * Supports arguments if the message (including format specifiers) is a string literal. Otherwise the use uf * LOG_ARG_DBG (and related macros) are needed. diff --git a/include/liblwm2m.h b/include/liblwm2m.h index 9a091915..6e44880b 100644 --- a/include/liblwm2m.h +++ b/include/liblwm2m.h @@ -924,6 +924,35 @@ int lwm2m_bootstrap_read(lwm2m_context_t * contextP, void * sessionH, lwm2m_uri_ #endif #endif +/* Logging related public functionality */ + +/* Logging level values used for preprocessor */ +#define LWM2M_DBG (10) +#define LWM2M_INFO (20) +#define LWM2M_WARN (30) +#define LWM2M_ERR (40) +#define LWM2M_FATAL (50) +#define LWM2M_LOG_DISABLED (0xff) + +#ifndef LWM2M_LOG_LEVEL +#define LWM2M_LOG_LEVEL LWM2M_LOG_DISABLED +#endif + +/** Logging levels */ +typedef enum { + LWM2M_LOGGING_DBG = (uint8_t)LWM2M_DBG, + LWM2M_LOGGING_INFO = (uint8_t)LWM2M_INFO, + LWM2M_LOGGING_WARN = (uint8_t)LWM2M_WARN, + LWM2M_LOGGING_ERR = (uint8_t)LWM2M_ERR, + LWM2M_LOGGING_FATAL = (uint8_t)LWM2M_FATAL +} lwm2m_logging_level_t; + +/** The default log handler for an log entry. To define a custom log handler define `LWM2M_LOG_CUSTOM_HANDLER` and + * implement a function with this signature. + * This function should not be called directly. Use the logging macros instead. */ +void lwm2m_log_handler(lwm2m_logging_level_t level, const char *const msg, const char *const func, const int line, + const char *const file); + #ifdef __cplusplus } #endif