mirror of
https://github.com/KjellKod/g3log.git
synced 2024-12-13 10:42:56 +01:00
Fix dangling else in LOG and LOGF macros (#231)
* Fix dangling else in LOG and LOGF macros Closes #224 * added unit test
This commit is contained in:
parent
e7d3b9d7b1
commit
0ddfd6dccc
@ -145,7 +145,7 @@ namespace g3 {
|
|||||||
|
|
||||||
|
|
||||||
// LOG(level) is the API for the stream log
|
// 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
|
// 'Conditional' stream log
|
||||||
@ -209,7 +209,7 @@ And here is possible output
|
|||||||
: Width trick: 10
|
: Width trick: 10
|
||||||
: A string \endverbatim */
|
: A string \endverbatim */
|
||||||
#define LOGF(level, printf_like_message, ...) \
|
#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
|
// Conditional log printf syntax
|
||||||
#define LOGF_IF(level,boolean_expression, printf_like_message, ...) \
|
#define LOGF_IF(level,boolean_expression, printf_like_message, ...) \
|
||||||
|
@ -269,6 +269,43 @@ TEST(LogTest, LOG) {
|
|||||||
ASSERT_TRUE(verifyContent(file_content, t_warning3));
|
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) {
|
TEST(LogTest, LOG_F_IF) {
|
||||||
std::string file_content;
|
std::string file_content;
|
||||||
|
Loading…
Reference in New Issue
Block a user