Module: sip-router
Branch: master
Commit: 34378c35b7cd037051af71081a9fa4d8b188c157
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=34378c3…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Fri May 17 09:56:34 2013 +0200
core: updated dprint api to enable support for debug level per module
- a callback can be registered to return the log level based on module
name
---
dprint.c | 19 ++++++++++++++++++-
dprint.h | 15 +++++++++++----
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/dprint.c b/dprint.c
index 12259d4..b99174d 100644
--- a/dprint.c
+++ b/dprint.c
@@ -115,12 +115,29 @@ int log_facility_fixup(void *handle, str *gname, str *name, void
**val)
/* the local debug log level */
static int _local_debug_level = UNSET_LOCAL_DEBUG_LEVEL;
+/* callback to get per module debug level */
+static get_module_debug_level_f _module_debug_level = NULL;
+
+/**
+ * @brief set callback function for per module debug level
+ */
+void set_module_debug_level_cb(get_module_debug_level_f f)
+{
+ _module_debug_level = f;
+}
/**
* @brief return the log level - the local one if it set,
* otherwise the global value
*/
-int get_debug_level(void) {
+int get_debug_level(char *mname, int mnlen) {
+ int mlevel = L_DBG;
+ /*important -- no LOGs inside, because it will loop */
+ if(unlikely(_module_debug_level!=NULL && mnlen>0)) {
+ if(_module_debug_level(mname, mnlen, &mlevel)==0) {
+ return mlevel;
+ }
+ }
return (_local_debug_level != UNSET_LOCAL_DEBUG_LEVEL) ?
_local_debug_level : cfg_get(core, core_cfg, debug);
}
diff --git a/dprint.h b/dprint.h
index 285c9f1..0842988 100644
--- a/dprint.h
+++ b/dprint.h
@@ -59,8 +59,10 @@
#ifdef NO_DEBUG
# ifdef MOD_NAME
# define LOC_INFO MOD_NAME ": "
+# define LOG_MNAME MOD_NAME
# else
# define LOC_INFO "<core>: "
+# define LOG_MNAME "core"
# endif
#else
# define XCT2STR(i) #i
@@ -68,8 +70,10 @@
#
# ifdef MOD_NAME
# define LOC_INFO MOD_NAME " [" __FILE__ ":" CT2STR(__LINE__)
"]: "
+# define LOG_MNAME MOD_NAME
# else
# define LOC_INFO "<core> [" __FILE__ ":" CT2STR(__LINE__)
"]: "
+# define LOG_MNAME "core"
# endif
#
# ifdef NO_LOG
@@ -77,6 +81,7 @@
# endif
#endif /* NO_DEBUG */
+#define LOG_MNAME_LEN (sizeof(LOG_MNAME)-1)
/*
* Log levels
@@ -121,11 +126,13 @@ struct log_level_info {
};
/** @brief per process debug level handling */
-int get_debug_level(void);
+int get_debug_level(char *mname, int mnlen);
void set_local_debug_level(int level);
void reset_local_debug_level(void);
+typedef int (*get_module_debug_level_f)(char *mname, int mnlen, int *mlevel);
+void set_module_debug_level_cb(get_module_debug_level_f f);
-#define is_printable(level) (get_debug_level()>=(level))
+#define is_printable(level) (get_debug_level(LOG_MNAME, LOG_MNAME_LEN)>=(level))
extern struct log_level_info log_level_info[];
extern char *log_name;
@@ -179,7 +186,7 @@ void dprint_term_color(char f, char b, str *obuf);
# ifdef __SUNPRO_C
# define LOG_(facility, level, prefix, fmt, ...) \
do { \
- if (unlikely(get_debuglevel() >= (level) && \
+ if (unlikely(get_debug_level(LOG_MNAME, LOG_MNAME_LEN) >= (level) && \
DPRINT_NON_CRIT)) { \
DPRINT_CRIT_ENTER; \
if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \
@@ -245,7 +252,7 @@ void dprint_term_color(char f, char b, str *obuf);
# else /* ! __SUNPRO_C */
# define LOG_(facility, level, prefix, fmt, args...) \
do { \
- if (get_debug_level() >= (level) && \
+ if (get_debug_level(LOG_MNAME, LOG_MNAME_LEN) >= (level) && \
DPRINT_NON_CRIT) { \
DPRINT_CRIT_ENTER; \
if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \