diff --git a/src/g3log/g3log.hpp b/src/g3log/g3log.hpp index 26fc41c..6dab3ee 100644 --- a/src/g3log/g3log.hpp +++ b/src/g3log/g3log.hpp @@ -145,7 +145,7 @@ namespace g3 { // LOG(level) is the API for the stream log -#define LOG(level) if(g3::logLevel(level)) INTERNAL_LOG_MESSAGE(level).stream() +#define LOG(level) if(!g3::logLevel(level)){ } else INTERNAL_LOG_MESSAGE(level).stream() // 'Conditional' stream log @@ -209,7 +209,7 @@ And here is possible output : Width trick: 10 : A string \endverbatim */ #define LOGF(level, printf_like_message, ...) \ - if(g3::logLevel(level)) INTERNAL_LOG_MESSAGE(level).capturef(printf_like_message, ##__VA_ARGS__) + if(!g3::logLevel(level)){ } else INTERNAL_LOG_MESSAGE(level).capturef(printf_like_message, ##__VA_ARGS__) // Conditional log printf syntax #define LOGF_IF(level,boolean_expression, printf_like_message, ...) \ diff --git a/test_unit/test_io.cpp b/test_unit/test_io.cpp index 9dd592a..b088757 100644 --- a/test_unit/test_io.cpp +++ b/test_unit/test_io.cpp @@ -269,6 +269,43 @@ TEST(LogTest, LOG) { ASSERT_TRUE(verifyContent(file_content, t_warning3)); } +TEST(LogTest, LOG_after_if) { + std::string file_content; + { + RestoreFileLogger logger(log_directory); + if(false == file_content.empty()) + LOG(INFO) << "This-should-NOT-show-up"; + else + LOG(INFO) << "This-should-show-up"; + + logger.reset(); // force flush of logger + file_content = readFileToText(logger.logFile()); + } + + ASSERT_FALSE(verifyContent(file_content, "This-should-NOT-show-up")); + ASSERT_TRUE(verifyContent(file_content, "This-should-show-up")); +} + + +TEST(LogTest, LOG_after_if_with_parentesis) { + std::string file_content; + { + RestoreFileLogger logger(log_directory); + if(false == file_content.empty()) { + LOG(INFO) << "This-should-NOT-show-up"; + } else { + LOG(INFO) << "This-should-show-up"; + } + + logger.reset(); // force flush of logger + file_content = readFileToText(logger.logFile()); + } + + ASSERT_FALSE(verifyContent(file_content, "This-should-NOT-show-up")); + ASSERT_TRUE(verifyContent(file_content, "This-should-show-up")); +} + + TEST(LogTest, LOG_F_IF) { std::string file_content;