2017-10-13 07:04:31 +08:00
|
|
|
/*
|
2018-03-09 21:26:33 +08:00
|
|
|
* This content is released under the MIT License as specified in https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE
|
|
|
|
*/
|
2017-10-13 07:04:31 +08:00
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
|
|
|
|
TEST_CASE("debug and trace w/o format string", "[macros]]")
|
|
|
|
{
|
2017-11-06 18:39:04 +08:00
|
|
|
prepare_logdir();
|
|
|
|
std::string filename = "logs/simple_log";
|
|
|
|
|
|
|
|
auto logger = spdlog::create<spdlog::sinks::simple_file_sink_mt>("logger", filename);
|
|
|
|
logger->set_pattern("%v");
|
|
|
|
logger->set_level(spdlog::level::trace);
|
|
|
|
|
|
|
|
SPDLOG_TRACE(logger, "Test message 1");
|
2018-03-09 21:26:33 +08:00
|
|
|
// SPDLOG_DEBUG(logger, "Test message 2");
|
2017-11-06 18:39:04 +08:00
|
|
|
SPDLOG_DEBUG(logger, "Test message 2");
|
|
|
|
logger->flush();
|
|
|
|
|
|
|
|
REQUIRE(ends_with(file_contents(filename), "Test message 2\n"));
|
|
|
|
REQUIRE(count_lines(filename) == 2);
|
2017-10-13 07:04:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("debug and trace with format strings", "[macros]]")
|
|
|
|
{
|
2017-11-06 18:39:04 +08:00
|
|
|
prepare_logdir();
|
|
|
|
std::string filename = "logs/simple_log";
|
2017-10-13 07:04:31 +08:00
|
|
|
|
2017-11-06 18:39:04 +08:00
|
|
|
auto logger = spdlog::create<spdlog::sinks::simple_file_sink_mt>("logger", filename);
|
|
|
|
logger->set_pattern("%v");
|
|
|
|
logger->set_level(spdlog::level::trace);
|
2017-10-13 07:04:31 +08:00
|
|
|
|
2017-10-13 07:15:49 +08:00
|
|
|
#if !defined(SPDLOG_FMT_PRINTF)
|
2017-11-06 18:39:04 +08:00
|
|
|
SPDLOG_TRACE(logger, "Test message {}", 1);
|
2018-03-09 21:26:33 +08:00
|
|
|
// SPDLOG_DEBUG(logger, "Test message 2");
|
2017-11-06 18:39:04 +08:00
|
|
|
SPDLOG_DEBUG(logger, "Test message {}", 222);
|
2017-10-13 07:15:49 +08:00
|
|
|
#else
|
2017-11-06 18:39:04 +08:00
|
|
|
SPDLOG_TRACE(logger, "Test message %d", 1);
|
2018-03-09 21:26:33 +08:00
|
|
|
// SPDLOG_DEBUG(logger, "Test message 2");
|
2017-11-06 18:39:04 +08:00
|
|
|
SPDLOG_DEBUG(logger, "Test message %d", 222);
|
2017-10-13 07:15:49 +08:00
|
|
|
#endif
|
|
|
|
|
2017-11-06 18:39:04 +08:00
|
|
|
logger->flush();
|
2017-10-13 07:04:31 +08:00
|
|
|
|
2017-11-06 18:39:04 +08:00
|
|
|
REQUIRE(ends_with(file_contents(filename), "Test message 222\n"));
|
|
|
|
REQUIRE(count_lines(filename) == 2);
|
2017-10-13 07:04:31 +08:00
|
|
|
}
|