Module: kamailio
Branch: master
Commit: 03203d1baa5f185db8743a90f889e5483e90e911
URL:
https://github.com/kamailio/kamailio/commit/03203d1baa5f185db8743a90f889e54…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-06-12T13:43:31+02:00
core: new log macros allowing to use local log levels per module
- a variable has to be defined inside module like:
ksr_loglevels_t _ksr_loglevels_MODNAME = KSR_LOGLEVELS_DEFAULTS;
- for example, for pdb module:
ksr_loglevels_t _ksr_loglevels_pdb = KSR_LOGLEVELS_DEFAULTS;
- then use LLM_XYZ() macro instead of LM_XYZ() - for example, use
LLM_INFO() instead of LM_INFO()
---
Modified: src/core/dprint.h
---
Diff:
https://github.com/kamailio/kamailio/commit/03203d1baa5f185db8743a90f889e54…
Patch:
https://github.com/kamailio/kamailio/commit/03203d1baa5f185db8743a90f889e54…
---
diff --git a/src/core/dprint.h b/src/core/dprint.h
index 993a6ebb826..13957b269c9 100644
--- a/src/core/dprint.h
+++ b/src/core/dprint.h
@@ -109,6 +109,22 @@
#define LOG2SYSLOG_LEVEL(level) \
(log_level_info[(level) - (L_ALERT)].syslog_level)
+/**
+ *
+ */
+typedef struct ksr_loglevels {
+ int ll_alert;
+ int ll_bug;
+ int ll_crit;
+ int ll_err;
+ int ll_warn;
+ int ll_notice;
+ int ll_info;
+ int ll_dbg;
+} ksr_loglevels_t;
+
+#define KSR_LOGLEVELS_DEFAULTS {L_ALERT, L_BUG, L_CRIT2, L_ERR, L_WARN, \
+ L_NOTICE, L_INFO, L_DBG}
/**
* data fileds used for structured logging
*/
@@ -406,6 +422,21 @@ void log_prefix_init(void);
/* obsolete, do not use */
#define DEBUG(...) DBG(__VA_ARGS__)
+/* use local log level mapping (not implemented for sun) */
+#define LLM_ALERT(...) LOG(L_ALERT, __VA_ARGS__)
+#define LLM_BUG(...) LOG(L_BUG, __VA_ARGS__)
+#define LLM_ERR(...) LOG(L_ERR, __VA_ARGS__)
+#define LLM_WARN(...) LOG(L_WARN, __VA_ARGS__)
+#define LLM_NOTICE(...) LOG(L_NOTICE, __VA_ARGS__)
+#define LLM_INFO(...) LOG(L_INFO, __VA_ARGS__)
+#define LLM_CRIT(...) LOG(L_CRIT2, __VA_ARGS__)
+
+#ifdef NO_DEBUG
+#define LLM_DBG(...)
+#else
+#define LLM_DBG(...) LOG(L_DBG, __VA_ARGS__)
+#endif
+
#else /* ! __SUNPRO_C */
#define NPRL(fmt, args...) LOG(L_NPRL, fmt, ##args)
#define ALERT(fmt, args...) LOG(L_ALERT, fmt, ##args)
@@ -425,6 +456,29 @@ void log_prefix_init(void);
/* obsolete, do not use */
#define DEBUG(fmt, args...) DBG(fmt, ##args)
+#ifdef MOD_NAMEID
+
+#define KSR_LLMODVAR_COMBINEZ(X,Y) X##Y
+#define KSR_LLMODVAR_COMBINE(X,Y) KSR_LLMODVAR_COMBINEZ(X,Y)
+#define KSR_LLMODVAR KSR_LLMODVAR_COMBINE(_ksr_loglevels_,MOD_NAMEID)
+
+/* use local log level mapping */
+#define LLM_ALERT(fmt, args...) LOG(KSR_LLMODVAR.alert, fmt, ##args)
+#define LLM_BUG(fmt, args...) LOG(KSR_LLMODVAR.buf, fmt, ##args)
+#define LLM_ERR(fmt, args...) LOG(KSR_LLMODVAR.bug, fmt, ##args)
+#define LLM_WARN(fmt, args...) LOG(KSR_LLMODVAR.warn, fmt, ##args)
+#define LLM_NOTICE(fmt, args...) LOG(KSR_LLMODVAR.notice, fmt, ##args)
+#define LLM_INFO(fmt, args...) LOG(KSR_LLMODVAR.ll_info, fmt, ##args)
+#define LLM_CRIT(fmt, args...) LOG(KSR_LLMODVAR.crit, fmt, ##args)
+
+#ifdef NO_DEBUG
+#define LLM_DBG(fmt, args...)
+#else
+#define LLM_DBG(fmt, args...) LOG(KSR_LLMODVAR.ll_dbg, fmt, ##args)
+#endif
+
+#endif /* MOD_NAMEID */
+
#endif /* __SUNPRO_C */