From c878b6a37dd87f57c9db8754a9e30e2ea713220c Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Tue, 27 Jun 2017 10:42:09 +0300 Subject: review fixes --- base/base_tests/logging_test.cpp | 18 ++++++++++++++++++ base/logging.hpp | 8 ++++++++ 2 files changed, 26 insertions(+) (limited to 'base') diff --git a/base/base_tests/logging_test.cpp b/base/base_tests/logging_test.cpp index ff5e50ad16..365db44668 100644 --- a/base/base_tests/logging_test.cpp +++ b/base/base_tests/logging_test.cpp @@ -18,6 +18,13 @@ namespace g_SomeFunctionCalled = true; return 3; } + + bool g_NegativeFunctionCalled; + bool NegativeFunction() + { + g_NegativeFunctionCalled = true; + return false; + } } UNIT_TEST(Logging_Level) @@ -43,3 +50,14 @@ UNIT_TEST(NullMessage) char const * ptr = 0; LOG(LINFO, ("Null message test", ptr)); } + +UNIT_TEST(Logging_ConditionalLog) +{ + g_SomeFunctionCalled = false; + CLOG(LINFO, SomeFunction(), ("This should not pass")); + TEST(g_SomeFunctionCalled, ()); + + g_NegativeFunctionCalled = false; + CLOG(LWARNING, NegativeFunction(), ("This should pass")); + TEST(g_NegativeFunctionCalled, ()); +} diff --git a/base/logging.hpp b/base/logging.hpp index 163041e0fb..147958938a 100644 --- a/base/logging.hpp +++ b/base/logging.hpp @@ -87,3 +87,11 @@ using ::my::LCRITICAL; if ((level) >= ::my::g_LogLevel) \ ::my::LogMessage(level, my::SrcPoint(), ::my::impl::Message msg); \ } while (false) + +// Conditional log. Logs @msg with level @level in case when @X returns false. +#define CLOG(level, X, msg) \ + do \ + { \ + if (!X) \ + LOG(level, (SRC(), "CLOG(" #X ")", ::my::impl::Message msg)); \ + } while (false) -- cgit v1.2.3