Ver código fonte

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
Daniel-Constantin Mierla 14 anos atrás
pai
commit
0d2716bcaf
2 arquivos alterados com 44 adições e 3 exclusões
  1. 36 0
      dprint.c
  2. 8 3
      dprint.h

+ 36 - 0
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;
+}

+ 8 - 3
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))){ \