diff --git a/layout/base/LayoutLogging.cpp b/layout/base/LayoutLogging.cpp index 661ddcecf5e..df4f5ab3db3 100644 --- a/layout/base/LayoutLogging.cpp +++ b/layout/base/LayoutLogging.cpp @@ -24,11 +24,19 @@ namespace detail { void LayoutLogWarning(const char* aStr, const char* aExpr, const char* aFile, int32_t aLine) { - MOZ_LOG(GetLayoutLog(), - mozilla::LogLevel::Warning, - ("[%d] WARNING: %s: '%s', file %s, line %d", - base::GetCurrentProcId(), - aStr, aExpr, aFile, aLine)); + if (aExpr) { + MOZ_LOG(GetLayoutLog(), + mozilla::LogLevel::Warning, + ("[%d] WARNING: %s: '%s', file %s, line %d", + base::GetCurrentProcId(), + aStr, aExpr, aFile, aLine)); + } else { + MOZ_LOG(GetLayoutLog(), + mozilla::LogLevel::Warning, + ("[%d] WARNING: %s: file %s, line %d", + base::GetCurrentProcId(), + aStr, aFile, aLine)); + } } } // namespace detail diff --git a/layout/base/LayoutLogging.h b/layout/base/LayoutLogging.h index 5da1b1124fb..377bebc9111 100644 --- a/layout/base/LayoutLogging.h +++ b/layout/base/LayoutLogging.h @@ -17,7 +17,7 @@ PRLogModuleInfo* GetLayoutLog(); * Use the layout log to warn if a given condition is false. * * This is only enabled in debug builds and the logging is only displayed if - * the environmental variable NSPR_LOG_MODULES includes "layout:2" (or higher). + * the environmental variable NSPR_LOG_MODULES includes "layout:2" (or higher). */ #ifdef DEBUG #define LAYOUT_WARN_IF_FALSE(_cond, _msg) \ @@ -33,6 +33,25 @@ PRLogModuleInfo* GetLayoutLog(); PR_END_MACRO #endif +/** + * Use the layout log to emit a warning with the same format as NS_WARNING. + * + * This is only enabled in debug builds and the logging is only displayed if + * the environmental variable NSPR_LOG_MODULES includes "layout:2" (or higher). + */ +#ifdef DEBUG +#define LAYOUT_WARNING(_msg) \ + PR_BEGIN_MACRO \ + if (MOZ_LOG_TEST(GetLayoutLog(), mozilla::LogLevel::Warning)) { \ + mozilla::detail::LayoutLogWarning(_msg, nullptr, __FILE__, __LINE__); \ + } \ + PR_END_MACRO +#else +#define LAYOUT_WARNING(_msg) \ + PR_BEGIN_MACRO \ + PR_END_MACRO +#endif + namespace mozilla { namespace detail {