diff options
author | Alex Zolotarev <alex@maps.me> | 2015-12-17 20:03:46 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-03-23 16:04:08 +0300 |
commit | 12f01e0ab9b92ccda7bb749ff5885a24cc660459 (patch) | |
tree | 9c52ef43a04d4893f96fb7ab68dcab18b3361337 /base | |
parent | f7197df58cc0ae1e77073bfe4e01b58ce3769ec7 (diff) |
Helper to suppress unnecessary log messages in unit tests.
Diffstat (limited to 'base')
-rw-r--r-- | base/logging.hpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/base/logging.hpp b/base/logging.hpp index 384d33d7d3..f97af58be6 100644 --- a/base/logging.hpp +++ b/base/logging.hpp @@ -25,6 +25,19 @@ namespace my void LogMessageDefault(LogLevel level, SrcPoint const & srcPoint, string const & msg); void LogMessageTests(LogLevel level, SrcPoint const & srcPoint, string const & msg); + + /// Scope Guard to temporarily suppress specific log level, for example, in unit tests: + /// ... + /// { + /// LogLevelSuppressor onlyLERRORAndLCriticalLogsAreEnabled; + /// TEST(SomeFunctionWhichHasDebugOrInfoOrWarningLogs(), ()); + /// } + struct LogLevelSuppressor + { + LogLevel m_old = g_LogLevel; + LogLevelSuppressor(LogLevel temporaryLogLevel = LERROR) { g_LogLevel = temporaryLogLevel; } + ~LogLevelSuppressor() { g_LogLevel = m_old; } + }; } using ::my::LDEBUG; |