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 199
 				} \
200 200
 			} while(0)
201 201
 			
202
-#		define LOG(level, fmt, ...) \
202
+#		ifdef LOG_FUNC_NAME
203
+#			define LOG(level, fmt, ...) \
204
+	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, "%s(): " fmt,\
205
+				_FUNC_NAME_, __VA_ARGS__)
206
+
207
+#			define LOG_FC(facility, level, fmt, ...) \
208
+	LOG_((facility), (level), LOC_INFO, "%s(): " fmt,\
209
+				_FUNC_NAME_, __VA_ARGS__)
210
+#		else /* LOG_FUNC_NAME */
211
+
212
+#			define LOG(level, fmt, ...) \
203 213
 	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt, __VA_ARGS__)
204
-#		define LOG_FC(facility, level, fmt, ...) \
214
+
215
+#			define LOG_FC(facility, level, fmt, ...) \
205 216
 	LOG_((facility), (level), LOC_INFO, fmt, __VA_ARGS__)
206 217
 
218
+#		endif /* LOG_FUNC_NAME */
219
+
207 220
 #	else /* ! __SUNPRO_C */
208 221
 #		define LOG_(facility, level, prefix, fmt, args...) \
209 222
 			do { \
... ...
@@ -248,11 +267,21 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
248 248
 				} \
249 249
 			} while(0)
250 250
 			
251
-#		define LOG(level, fmt, args...) \
251
+#		ifdef LOG_FUNC_NAME
252
+#			define LOG(level, fmt, args...) \
253
+	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, "%s(): " fmt ,\
254
+			_FUNC_NAME_, ## args)
255
+
256
+#			define LOG_FC(facility, level, fmt, args...) \
257
+	LOG_((facility), (level), LOC_INFO, "%s(): " fmt , _FUNC_NAME_, ## args)
258
+
259
+#		else /* LOG_FUNC_NAME */
260
+#			define LOG(level, fmt, args...) \
252 261
 	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt , ## args)
253
-#		define LOG_FC(facility, level, fmt, args...) \
262
+#			define LOG_FC(facility, level, fmt, args...) \
254 263
 	LOG_((facility), (level), LOC_INFO, fmt , ## args)
255
-		
264
+
265
+#		endif /* LOG_FUNC_NAME */
256 266
 #	endif /* __SUNPRO_C */
257 267
 #endif /* NO_LOG */
258 268