From b5f5f391edce0681da56c36b6e8ba1b27d32251f Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sat, 21 Mar 2020 13:08:29 -0400
Subject: [PATCH] Nop out debug logging in release builds

---
 indra/llcommon/llerror.h | 46 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/indra/llcommon/llerror.h b/indra/llcommon/llerror.h
index 0a782295550..ab29076b484 100644
--- a/indra/llcommon/llerror.h
+++ b/indra/llcommon/llerror.h
@@ -44,6 +44,7 @@ const int LL_ERR_NOERR = 0;
 #define RELEASE_SHOW_WARN // Define this if you want your release builds to show llwarn output.
 
 #ifdef _DEBUG
+#define ENABLE_DEBUG 1
 #define SHOW_DEBUG
 #define SHOW_WARN
 #define SHOW_INFO
@@ -51,10 +52,12 @@ const int LL_ERR_NOERR = 0;
 #else // _DEBUG
 
 #ifdef LL_RELEASE_WITH_DEBUG_INFO
+#define ENABLE_DEBUG 1
 #define SHOW_ASSERT
 #endif // LL_RELEASE_WITH_DEBUG_INFO
 
 #ifdef RELEASE_SHOW_DEBUG
+#define ENABLE_DEBUG 1
 #define SHOW_DEBUG
 #endif
 
@@ -289,6 +292,7 @@ namespace LLError
 }
 
 //this is cheaper than llcallstacks if no need to output other variables to call stacks. 
+#if ENABLE_DEBUG
 #define LL_PUSH_CALLSTACKS() LLError::LLCallStacks::push(__FUNCTION__, __LINE__)
 
 #define llcallstacks                                                                      \
@@ -300,6 +304,20 @@ namespace LLError
 		LLError::End();                    \
 		LLError::LLCallStacks::end(_out) ; \
 	}
+#else
+#define LL_PUSH_CALLSTACKS()
+
+#define llcallstacks                                                                      \
+	if (false)																			  \
+	{                                                                                     \
+       std::ostringstream* _out = LLError::LLCallStacks::insert(__FUNCTION__, __LINE__) ; \
+       (*_out)
+
+#define llcallstacksendl                   \
+		LLError::End();                    \
+		LLError::LLCallStacks::end(_out) ; \
+	}
+#endif
 
 #define LL_CLEAR_CALLSTACKS() LLError::LLCallStacks::clear()
 #define LL_PRINT_CALLSTACKS() LLError::LLCallStacks::print() 
@@ -346,6 +364,30 @@ typedef LLError::NoClassInfo _LL_CLASS_TO_LOG;
 			std::ostringstream* _out = LLError::Log::out(); \
 			(*_out)
 
+#ifdef ENABLE_DEBUG
+
+#define lllog_debug(level, once, ...)                                         \
+	do {                                                                \
+		const char* tags[] = {"", ##__VA_ARGS__};                       \
+		static LLError::CallSite _site(lllog_site_args_(level, once, tags)); \
+		lllog_test_debug_()
+
+#define lllog_test_debug_()                                       \
+		if (LL_UNLIKELY(_site.shouldLog()))                 \
+		{                                                   \
+			std::ostringstream* _out = LLError::Log::out(); \
+			(*_out)
+#else
+#define lllog_debug(level, once, ...)                                         \
+	do {                                                                \
+		if (false)                 \
+		{                                                   \
+			const char* tags[] = {"", ##__VA_ARGS__};                       \
+			LLError::CallSite _site(lllog_site_args_(level, once, tags)); \
+			std::ostringstream* _out = LLError::Log::out(); \
+			(*_out)
+#endif
+
 #define lllog_site_args_(level, once, tags)                 \
 	level, __FILE__, __LINE__, typeid(_LL_CLASS_TO_LOG),    \
 	__FUNCTION__, once, &tags[1], LL_ARRAY_SIZE(tags)-1
@@ -376,7 +418,7 @@ typedef LLError::NoClassInfo _LL_CLASS_TO_LOG;
 // NEW Macros for debugging, allow the passing of a string tag
 
 // Pass comma separated list of tags (currently only supports up to 0, 1, or 2)
-#define LL_DEBUGS(...)	lllog(LLError::LEVEL_DEBUG, false, ##__VA_ARGS__)
+#define LL_DEBUGS(...)	lllog_debug(LLError::LEVEL_DEBUG, false, ##__VA_ARGS__)
 #define LL_INFOS(...)	lllog(LLError::LEVEL_INFO, false, ##__VA_ARGS__)
 #define LL_WARNS(...)	lllog(LLError::LEVEL_WARN, false, ##__VA_ARGS__)
 #define LL_ERRS(...)	lllog(LLError::LEVEL_ERROR, false, ##__VA_ARGS__)
@@ -386,7 +428,7 @@ typedef LLError::NoClassInfo _LL_CLASS_TO_LOG;
 
 // Only print the log message once (good for warnings or infos that would otherwise
 // spam the log file over and over, such as tighter loops).
-#define LL_DEBUGS_ONCE(...)	lllog(LLError::LEVEL_DEBUG, true, ##__VA_ARGS__)
+#define LL_DEBUGS_ONCE(...)	lllog_debug(LLError::LEVEL_DEBUG, true, ##__VA_ARGS__)
 #define LL_INFOS_ONCE(...)	lllog(LLError::LEVEL_INFO, true, ##__VA_ARGS__)
 #define LL_WARNS_ONCE(...)	lllog(LLError::LEVEL_WARN, true, ##__VA_ARGS__)
 
-- 
GitLab