Browse code

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 authored on 07/03/2011 16:08:15
Showing 2 changed files
... ...
@@ -104,3 +104,39 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val)
104 104
 	*val = (void *)(long)i;
105 105
 	return 0;
106 106
 }
107
+
108
+
109
+/**
110
+ * per process debug log level (local)
111
+ */
112
+
113
+/* value for unset local log level  */
114
+#define UNSET_LOCAL_DEBUG_LEVEL	-255
115
+
116
+/* the local debug log level */
117
+static int _local_debug_level = UNSET_LOCAL_DEBUG_LEVEL;
118
+
119
+/**
120
+ * @brief return the log level - the local one if it set,
121
+ *   otherwise the global value
122
+ */
123
+int get_debug_level(void) {
124
+	return (_local_debug_level != UNSET_LOCAL_DEBUG_LEVEL) ?
125
+				_local_debug_level : cfg_get(core, core_cfg, debug);
126
+}
127
+
128
+/**
129
+ * @brief set the local debug log level
130
+ */
131
+void set_local_debug_level(int level)
132
+{
133
+	_local_debug_level = level;
134
+}
135
+
136
+/**
137
+ * @brief reset the local debug log level
138
+ */
139
+void reset_local_debug_level(void)
140
+{
141
+	_local_debug_level = UNSET_LOCAL_DEBUG_LEVEL;
142
+}
... ...
@@ -118,7 +118,12 @@ struct log_level_info {
118 118
 	int syslog_level;
119 119
 };
120 120
 
121
-#define is_printable(level) (cfg_get(core, core_cfg, debug)>=(level))
121
+/** @brief per process debug level handling */
122
+int get_debug_level(void);
123
+void set_local_debug_level(int level);
124
+void reset_local_debug_level(void);
125
+
126
+#define is_printable(level) (get_debug_level()>=(level))
122 127
 extern struct log_level_info log_level_info[];
123 128
 extern char *log_name;
124 129
 
... ...
@@ -167,7 +172,7 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
167 167
 #	ifdef __SUNPRO_C
168 168
 #		define LOG_(facility, level, prefix, fmt, ...) \
169 169
 			do { \
170
-				if (unlikely(cfg_get(core, core_cfg, debug) >= (level) && \
170
+				if (unlikely(get_debuglevel() >= (level) && \
171 171
 						DPRINT_NON_CRIT)) { \
172 172
 					DPRINT_CRIT_ENTER; \
173 173
 					if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \
... ...
@@ -229,7 +234,7 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
229 229
 #	else /* ! __SUNPRO_C */
230 230
 #		define LOG_(facility, level, prefix, fmt, args...) \
231 231
 			do { \
232
-				if (cfg_get(core, core_cfg, debug) >= (level) && \
232
+				if (get_debug_level() >= (level) && \
233 233
 						DPRINT_NON_CRIT) { \
234 234
 					DPRINT_CRIT_ENTER; \
235 235
 					if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \