[sr-dev] git:master: core: print function name in LOG messages

Andrei Pelinescu-Onciul andrei at iptel.org
Thu Sep 16 14:13:19 CEST 2010


Module: sip-router
Branch: master
Commit: 8af71cf262688bd80294dbd8a725a0e2e447c196
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8af71cf262688bd80294dbd8a725a0e2e447c196

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Sat Sep 11 19:11:23 2010 +0200

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.

---

 dprint.h |   39 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/dprint.h b/dprint.h
index c3cb5dc..8f50b1f 100644
--- a/dprint.h
+++ b/dprint.h
@@ -38,12 +38,18 @@
 #include "cfg_core.h"
 
 
+/** if defined the function name will also be logged. */
+#ifdef NO_LOG_FUNC_NAME
+#	undef LOG_FUNC_NAME
+#endif /* NO_LOG_FUNC_NAME */
+
 /* C >= 99 has __func__, older gcc versions have __FUNCTION__ */
 #if __STDC_VERSION__ < 199901L
 #	if __GNUC__ >= 2
 #		define _FUNC_NAME_ __FUNCTION__
 #	else
 #		define _FUNC_NAME_ ""
+#		undef LOG_FUNC_NAME
 #	endif
 #else
 #	define _FUNC_NAME_ __func__
@@ -199,11 +205,24 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
 				} \
 			} while(0)
 			
-#		define LOG(level, fmt, ...) \
+#		ifdef LOG_FUNC_NAME
+#			define LOG(level, fmt, ...) \
+	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, "%s(): " fmt,\
+				_FUNC_NAME_, __VA_ARGS__)
+
+#			define LOG_FC(facility, level, fmt, ...) \
+	LOG_((facility), (level), LOC_INFO, "%s(): " fmt,\
+				_FUNC_NAME_, __VA_ARGS__)
+#		else /* LOG_FUNC_NAME */
+
+#			define LOG(level, fmt, ...) \
 	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt, __VA_ARGS__)
-#		define LOG_FC(facility, level, fmt, ...) \
+
+#			define LOG_FC(facility, level, fmt, ...) \
 	LOG_((facility), (level), LOC_INFO, fmt, __VA_ARGS__)
 
+#		endif /* LOG_FUNC_NAME */
+
 #	else /* ! __SUNPRO_C */
 #		define LOG_(facility, level, prefix, fmt, args...) \
 			do { \
@@ -248,11 +267,21 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
 				} \
 			} while(0)
 			
-#		define LOG(level, fmt, args...) \
+#		ifdef LOG_FUNC_NAME
+#			define LOG(level, fmt, args...) \
+	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, "%s(): " fmt ,\
+			_FUNC_NAME_, ## args)
+
+#			define LOG_FC(facility, level, fmt, args...) \
+	LOG_((facility), (level), LOC_INFO, "%s(): " fmt , _FUNC_NAME_, ## args)
+
+#		else /* LOG_FUNC_NAME */
+#			define LOG(level, fmt, args...) \
 	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt , ## args)
-#		define LOG_FC(facility, level, fmt, args...) \
+#			define LOG_FC(facility, level, fmt, args...) \
 	LOG_((facility), (level), LOC_INFO, fmt , ## args)
-		
+
+#		endif /* LOG_FUNC_NAME */
 #	endif /* __SUNPRO_C */
 #endif /* NO_LOG */
 




More information about the sr-dev mailing list