Removed lazy argument evaluation from macros
This commit is contained in:
		@@ -60,15 +60,14 @@ protected:
 | 
				
			|||||||
        if (msg.source.empty())
 | 
					        if (msg.source.empty())
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // Note: function call inside '()' to avoid macro expansion
 | 
					            // Note: function call inside '()' to avoid macro expansion
 | 
				
			||||||
            err = (sd_journal_send)(
 | 
					            err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level),
 | 
				
			||||||
                "MESSAGE=%.*s", static_cast<int>(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level),
 | 
					 | 
				
			||||||
                "SYSLOG_IDENTIFIER=%.*s", static_cast<int>(msg.logger_name.size()), msg.logger_name.data(), nullptr);
 | 
					                "SYSLOG_IDENTIFIER=%.*s", static_cast<int>(msg.logger_name.size()), msg.logger_name.data(), nullptr);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level),
 | 
					            err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level),
 | 
				
			||||||
                "SYSLOG_IDENTIFIER=%.*s", static_cast<int>(msg.logger_name.size()), msg.logger_name.data(),
 | 
					                "SYSLOG_IDENTIFIER=%.*s", static_cast<int>(msg.logger_name.size()), msg.logger_name.data(), "CODE_FILE=%s",
 | 
				
			||||||
                "CODE_FILE=%s", msg.source.filename, "CODE_LINE=%d", msg.source.line, "CODE_FUNC=%s", msg.source.funcname, nullptr);
 | 
					                msg.source.filename, "CODE_LINE=%d", msg.source.line, "CODE_FUNC=%s", msg.source.funcname, nullptr);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (err)
 | 
					        if (err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -285,12 +285,7 @@ inline void critical(wstring_view_t fmt, const Args &... args)
 | 
				
			|||||||
// SPDLOG_LEVEL_OFF
 | 
					// SPDLOG_LEVEL_OFF
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SPDLOG_LOGGER_CALL(logger, level, ...)                                                                                             \
 | 
					#define SPDLOG_LOGGER_CALL(logger, level, ...) (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__);
 | 
				
			||||||
    do                                                                                                                                     \
 | 
					 | 
				
			||||||
    {                                                                                                                                      \
 | 
					 | 
				
			||||||
        if ((logger)->should_log(level) || (logger)->should_backtrace())                                                                   \
 | 
					 | 
				
			||||||
            (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__);                                    \
 | 
					 | 
				
			||||||
    } while (0)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
 | 
					#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
 | 
				
			||||||
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
 | 
					#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,7 @@ TEST_CASE("disable param evaluation", "[macros]")
 | 
				
			|||||||
    SPDLOG_TRACE("Test message {}", throw std::runtime_error("Should not be evaluated"));
 | 
					    SPDLOG_TRACE("Test message {}", throw std::runtime_error("Should not be evaluated"));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST_CASE("compile with reference to logger", "[macros]")
 | 
					TEST_CASE("pass logger pointer", "[macros]")
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    auto logger = spdlog::create<spdlog::sinks::null_sink_mt>("refmacro");
 | 
					    auto logger = spdlog::create<spdlog::sinks::null_sink_mt>("refmacro");
 | 
				
			||||||
    auto &ref = *logger;
 | 
					    auto &ref = *logger;
 | 
				
			||||||
@@ -49,11 +49,11 @@ TEST_CASE("compile with reference to logger", "[macros]")
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ensure that even if right macro level is on- don't evaluate if the logger's level is not high enough
 | 
					// ensure that even if right macro level is on- don't evaluate if the logger's level is not high enough
 | 
				
			||||||
TEST_CASE("disable param evaluation2", "[macros]")
 | 
					//TEST_CASE("disable param evaluation2", "[macros]")
 | 
				
			||||||
{
 | 
					//{
 | 
				
			||||||
    auto logger = std::make_shared<spdlog::logger>("test-macro");
 | 
					//    auto logger = std::make_shared<spdlog::logger>("test-macro");
 | 
				
			||||||
    logger->set_level(spdlog::level::off);
 | 
					//    logger->set_level(spdlog::level::off);
 | 
				
			||||||
    int x = 0;
 | 
					//    int x = 0;
 | 
				
			||||||
    SPDLOG_LOGGER_DEBUG(logger, "Test message {}", ++x);
 | 
					//    SPDLOG_LOGGER_DEBUG(logger, "Test message {}", ++x);
 | 
				
			||||||
    REQUIRE(x == 0);
 | 
					//    REQUIRE(x == 0);
 | 
				
			||||||
}
 | 
					//}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user