Module: sip-router
Branch: master
Commit: 0d2716bcafed9e6d3d9b920bc5137b1d726a891c
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0d2716b…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Mon Mar 7 17:08:15 2011 +0100
core: support to set debug level per process from cfg
- this is the part in the core dprinting system
- getting the debug level is a warapper around fetching the local debug
if it is set, otherwise returns the value of global parameter 'debug'
- by default per process debug log level is not set
---
dprint.c | 36 ++++++++++++++++++++++++++++++++++++
dprint.h | 11 ++++++++---
2 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/dprint.c b/dprint.c
index de6cb48..324d511 100644
--- a/dprint.c
+++ b/dprint.c
@@ -104,3 +104,39 @@ int log_facility_fixup(void *handle, str *gname, str *name, void
**val)
*val = (void *)(long)i;
return 0;
}
+
+
+/**
+ * per process debug log level (local)
+ */
+
+/* value for unset local log level */
+#define UNSET_LOCAL_DEBUG_LEVEL -255
+
+/* the local debug log level */
+static int _local_debug_level = UNSET_LOCAL_DEBUG_LEVEL;
+
+/**
+ * @brief return the log level - the local one if it set,
+ * otherwise the global value
+ */
+int get_debug_level(void) {
+ return (_local_debug_level != UNSET_LOCAL_DEBUG_LEVEL) ?
+ _local_debug_level : cfg_get(core, core_cfg, debug);
+}
+
+/**
+ * @brief set the local debug log level
+ */
+void set_local_debug_level(int level)
+{
+ _local_debug_level = level;
+}
+
+/**
+ * @brief reset the local debug log level
+ */
+void reset_local_debug_level(void)
+{
+ _local_debug_level = UNSET_LOCAL_DEBUG_LEVEL;
+}
diff --git a/dprint.h b/dprint.h
index c3f2b27..31ba4a2 100644
--- a/dprint.h
+++ b/dprint.h
@@ -118,7 +118,12 @@ struct log_level_info {
int syslog_level;
};
-#define is_printable(level) (cfg_get(core, core_cfg, debug)>=(level))
+/** @brief per process debug level handling */
+int get_debug_level(void);
+void set_local_debug_level(int level);
+void reset_local_debug_level(void);
+
+#define is_printable(level) (get_debug_level()>=(level))
extern struct log_level_info log_level_info[];
extern char *log_name;
@@ -167,7 +172,7 @@ int log_facility_fixup(void *handle, str *gname, str *name, void
**val);
# ifdef __SUNPRO_C
# define LOG_(facility, level, prefix, fmt, ...) \
do { \
- if (unlikely(cfg_get(core, core_cfg, debug) >= (level) && \
+ if (unlikely(get_debuglevel() >= (level) && \
DPRINT_NON_CRIT)) { \
DPRINT_CRIT_ENTER; \
if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \
@@ -229,7 +234,7 @@ int log_facility_fixup(void *handle, str *gname, str *name, void
**val);
# else /* ! __SUNPRO_C */
# define LOG_(facility, level, prefix, fmt, args...) \
do { \
- if (cfg_get(core, core_cfg, debug) >= (level) && \
+ if (get_debug_level() >= (level) && \
DPRINT_NON_CRIT) { \
DPRINT_CRIT_ENTER; \
if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \