Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gabime/spdlog.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgabime <gmelman1@gmail.com>2019-11-03 16:19:59 +0300
committergabime <gmelman1@gmail.com>2019-11-03 16:19:59 +0300
commitcae6c9ab361ffee0e2d7d2e4b89a333c88a1019d (patch)
tree4f26e1fe05016c7c956d553c1240bfc9e4c3b220
parent15b393193ad06d839d94011a03960c16369262fd (diff)
Removed lazy argument evaluation from macros
-rw-r--r--include/spdlog/details/file_helper-inl.h2
-rw-r--r--include/spdlog/details/os-inl.h2
-rw-r--r--include/spdlog/sinks/systemd_sink.h7
-rw-r--r--include/spdlog/spdlog.h7
-rw-r--r--tests/test_macros.cpp20
5 files changed, 16 insertions, 22 deletions
diff --git a/include/spdlog/details/file_helper-inl.h b/include/spdlog/details/file_helper-inl.h
index 669999b4..3c1d8056 100644
--- a/include/spdlog/details/file_helper-inl.h
+++ b/include/spdlog/details/file_helper-inl.h
@@ -30,7 +30,7 @@ SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
close();
filename_ = fname;
auto *mode = truncate ? SPDLOG_FILENAME_T("wb") : SPDLOG_FILENAME_T("ab");
-
+
for (int tries = 0; tries < open_tries_; ++tries)
{
// create containing folder if not exists already.
diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h
index 73a464c9..f03cf310 100644
--- a/include/spdlog/details/os-inl.h
+++ b/include/spdlog/details/os-inl.h
@@ -485,7 +485,7 @@ SPDLOG_INLINE bool create_dir(filename_t path)
return true;
}
- if(path.empty())
+ if (path.empty())
{
return false;
}
diff --git a/include/spdlog/sinks/systemd_sink.h b/include/spdlog/sinks/systemd_sink.h
index 2887e58e..cee889a4 100644
--- a/include/spdlog/sinks/systemd_sink.h
+++ b/include/spdlog/sinks/systemd_sink.h
@@ -60,15 +60,14 @@ protected:
if (msg.source.empty())
{
// Note: function call inside '()' to avoid macro expansion
- 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(), nullptr);
}
else
{
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(),
- "CODE_FILE=%s", msg.source.filename, "CODE_LINE=%d", msg.source.line, "CODE_FUNC=%s", msg.source.funcname, nullptr);
+ "SYSLOG_IDENTIFIER=%.*s", static_cast<int>(msg.logger_name.size()), msg.logger_name.data(), "CODE_FILE=%s",
+ msg.source.filename, "CODE_LINE=%d", msg.source.line, "CODE_FUNC=%s", msg.source.funcname, nullptr);
}
if (err)
diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h
index 401d22eb..9e0af330 100644
--- a/include/spdlog/spdlog.h
+++ b/include/spdlog/spdlog.h
@@ -285,12 +285,7 @@ inline void critical(wstring_view_t fmt, const Args &... args)
// SPDLOG_LEVEL_OFF
//
-#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)
+#define SPDLOG_LOGGER_CALL(logger, level, ...) (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__);
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
diff --git a/tests/test_macros.cpp b/tests/test_macros.cpp
index 83a95dbd..b18c1cbf 100644
--- a/tests/test_macros.cpp
+++ b/tests/test_macros.cpp
@@ -40,20 +40,20 @@ TEST_CASE("disable param evaluation", "[macros]")
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& ref = *logger;
+ auto &ref = *logger;
SPDLOG_LOGGER_TRACE(&ref, "Test message 1");
SPDLOG_LOGGER_DEBUG(&ref, "Test message 2");
}
// 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]")
-{
- 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);
-}
+//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);
+//}