logging: make LIBOSMOCORE_NO_LOGGING work as expected

The macro introduced in d02090bba538158c36fd838d4e50c47e40f11449 was not
enough: the actual logging macros are being used, i.e. by the fsm, so
wrap those as well, and provide a flag to disable this at build time.

Change-Id: Ia4c78abe5f198139f96ffa289998855be2477585
diff --git a/configure.ac b/configure.ac
index b36bd6f..a69f793 100644
--- a/configure.ac
+++ b/configure.ac
@@ -366,6 +366,17 @@
 	AC_DEFINE([PANIC_INFLOOP],[1],[Use infinite loop on panic rather than fprintf/abort])
 fi
 
+AC_ARG_ENABLE(log_macros,
+	[AS_HELP_STRING(
+		[--disable-log-macros],
+		[Disable logging macros that are also used internally to print information]
+	)],
+	[log_macros="yes"], [log_macros="no"])
+if test x"$log_macros" == x"yes"
+then
+	AC_DEFINE([LIBOSMOCORE_NO_LOGGING],[1],[Disable logging macros])
+fi
+
 AC_ARG_ENABLE(sanitize,
 	[AS_HELP_STRING(
 		[--enable-sanitize],
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index a95c478..18ad3ff 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -53,11 +53,15 @@
  *  \param[in] fmt format string
  *  \param[in] args variable argument list
  */
+#ifndef LIBOSMOCORE_NO_LOGGING
 #define LOGPC(ss, level, fmt, args...) \
 	do { \
 		if (log_check_level(ss, level)) \
 			logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args); \
 	} while(0)
+#else
+#define LOGPC(ss, level, fmt, args...)
+#endif
 
 /*! Log through the Osmocom logging framework with explicit source.
  *  If caller_file is passed as NULL, __FILE__ and __LINE__ are used
@@ -87,6 +91,7 @@
  *  \param[in] fmt format string
  *  \param[in] args variable argument list
  */
+#ifndef LIBOSMOCORE_NO_LOGGING
 #define LOGPSRCC(ss, level, caller_file, caller_line, cont, fmt, args...) \
 	do { \
 		if (log_check_level(ss, level)) {\
@@ -96,6 +101,9 @@
 				logp2(ss, level, __FILE__, __LINE__, cont, fmt, ##args); \
 		}\
 	} while(0)
+#else
+#define LOGPSRCC(ss, level, caller_file, caller_line, cont, fmt, args...)
+#endif
 
 /*! different log levels */
 #define LOGL_DEBUG	1	/*!< debugging information */