mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-24 09:31:34 +08:00
Fix #1262
This commit is contained in:
parent
1549ff12f1
commit
9369fe8c27
@ -69,6 +69,11 @@ SPDLOG_INLINE bool logger::should_log(level::level_enum msg_level) const
|
||||
return msg_level >= level_.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE bool logger::should_backtrace() const
|
||||
{
|
||||
return tracer_.enabled();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void logger::set_level(level::level_enum log_level)
|
||||
{
|
||||
level_.store(log_level);
|
||||
|
@ -319,8 +319,12 @@ public:
|
||||
#endif // _WIN32
|
||||
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
|
||||
// return true logging is enabled for the given level.
|
||||
bool should_log(level::level_enum msg_level) const;
|
||||
|
||||
// return true if backtrace logging is enabled.
|
||||
bool should_backtrace() const;
|
||||
|
||||
void set_level(level::level_enum log_level);
|
||||
|
||||
level::level_enum level() const;
|
||||
|
@ -285,7 +285,10 @@ inline void critical(wstring_view_t fmt, const Args &... args)
|
||||
// SPDLOG_LEVEL_OFF
|
||||
//
|
||||
|
||||
#define SPDLOG_LOGGER_CALL(logger, level, ...) logger->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
|
||||
#define SPDLOG_LOGGER_CALL(logger, level, ...) 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
|
||||
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
|
||||
|
@ -39,3 +39,13 @@ TEST_CASE("disable param evaluation", "[macros]")
|
||||
{
|
||||
SPDLOG_TRACE("Test message {}", throw std::runtime_error("Should not be evaluated"));
|
||||
}
|
||||
|
||||
// ensure that even if right macro level is on- don't eavluate if the logger's level is not high enough
|
||||
TEST_CASE("disable param evaluation2", "[macros]")
|
||||
{
|
||||
auto logger = std::make_shared<spdlog::logger>("test-macro");
|
||||
logger->set_level(spdlog::level::off);
|
||||
int x = 0;
|
||||
SPDLOG_LOGGER_DEBUG(logger, "Test message {}", ++x);
|
||||
REQUIRE(x == 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user