Browse code

core: print function name in LOG messages

Compile time define for printing the function name by default in
log messages. Can be turned on by compiling with -DLOG_FUNC_NAME
(e.g. make cfg extra_defs=-DLOG_FUNC_NAME) and turned off
by recompiling with -DNO_LOG_FUNC_NAME.
It's also turned off if the compiler does not support it (non C99
and no known workaround).
The default it's off.

Andrei Pelinescu-Onciul authored on 11/09/2010 17:11:23
Showing 1 changed files
... ...
@@ -38,12 +38,18 @@
38 38
 #include "cfg_core.h"
39 39
 
40 40
 
41
+/** if defined the function name will also be logged. */
42
+#ifdef NO_LOG_FUNC_NAME
43
+#	undef LOG_FUNC_NAME
44
+#endif /* NO_LOG_FUNC_NAME */
45
+
41 46
 /* C >= 99 has __func__, older gcc versions have __FUNCTION__ */
42 47
 #if __STDC_VERSION__ < 199901L
43 48
 #	if __GNUC__ >= 2
44 49
 #		define _FUNC_NAME_ __FUNCTION__
45 50
 #	else
46 51
 #		define _FUNC_NAME_ ""
52
+#		undef LOG_FUNC_NAME
47 53
 #	endif
48 54
 #else
49 55
 #	define _FUNC_NAME_ __func__
... ...
@@ -199,11 +205,24 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
199 205
 				} \
200 206
 			} while(0)
201 207
 			
202
-#		define LOG(level, fmt, ...) \
208
+#		ifdef LOG_FUNC_NAME
209
+#			define LOG(level, fmt, ...) \
210
+	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, "%s(): " fmt,\
211
+				_FUNC_NAME_, __VA_ARGS__)
212
+
213
+#			define LOG_FC(facility, level, fmt, ...) \
214
+	LOG_((facility), (level), LOC_INFO, "%s(): " fmt,\
215
+				_FUNC_NAME_, __VA_ARGS__)
216
+#		else /* LOG_FUNC_NAME */
217
+
218
+#			define LOG(level, fmt, ...) \
203 219
 	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt, __VA_ARGS__)
204
-#		define LOG_FC(facility, level, fmt, ...) \
220
+
221
+#			define LOG_FC(facility, level, fmt, ...) \
205 222
 	LOG_((facility), (level), LOC_INFO, fmt, __VA_ARGS__)
206 223
 
224
+#		endif /* LOG_FUNC_NAME */
225
+
207 226
 #	else /* ! __SUNPRO_C */
208 227
 #		define LOG_(facility, level, prefix, fmt, args...) \
209 228
 			do { \
... ...
@@ -248,11 +267,21 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
248 267
 				} \
249 268
 			} while(0)
250 269
 			
251
-#		define LOG(level, fmt, args...) \
270
+#		ifdef LOG_FUNC_NAME
271
+#			define LOG(level, fmt, args...) \
272
+	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, "%s(): " fmt ,\
273
+			_FUNC_NAME_, ## args)
274
+
275
+#			define LOG_FC(facility, level, fmt, args...) \
276
+	LOG_((facility), (level), LOC_INFO, "%s(): " fmt , _FUNC_NAME_, ## args)
277
+
278
+#		else /* LOG_FUNC_NAME */
279
+#			define LOG(level, fmt, args...) \
252 280
 	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt , ## args)
253
-#		define LOG_FC(facility, level, fmt, args...) \
281
+#			define LOG_FC(facility, level, fmt, args...) \
254 282
 	LOG_((facility), (level), LOC_INFO, fmt , ## args)
255
-		
283
+
284
+#		endif /* LOG_FUNC_NAME */
256 285
 #	endif /* __SUNPRO_C */
257 286
 #endif /* NO_LOG */
258 287