Browse Source

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 15 years ago
parent
commit
8af71cf262
1 changed files with 34 additions and 5 deletions
  1. 34 5
      dprint.h

+ 34 - 5
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 */