Skip to content

Commit

Permalink
logging: Make logging handler declaration public
Browse files Browse the repository at this point in the history
The logging handler function can be customized. Therefore it belongs
into to puplic header of Wakaama.
  • Loading branch information
LukasWoodtli committed May 24, 2024
1 parent 03fdb7b commit 447ec05
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
25 changes: 0 additions & 25 deletions core/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <inttypes.h>

Expand All @@ -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" : \
Expand All @@ -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.
Expand Down
29 changes: 29 additions & 0 deletions include/liblwm2m.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 447ec05

Please sign in to comment.