2015-05-16 01:30:37 +08:00
|
|
|
#include "includes.h"
|
|
|
|
|
|
|
|
template<class T>
|
2015-05-16 02:45:10 +08:00
|
|
|
std::string log_info(const T& what, spdlog::level::level_enum logger_level = spdlog::level::info)
|
|
|
|
{
|
2015-05-16 01:30:37 +08:00
|
|
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
|
|
|
|
|
|
|
spdlog::logger oss_logger("oss", oss_sink);
|
|
|
|
oss_logger.set_level(logger_level);
|
|
|
|
oss_logger.set_pattern("%v");
|
2016-07-03 08:43:55 +08:00
|
|
|
oss_logger.info(what);
|
2016-05-15 06:01:01 +08:00
|
|
|
|
2018-02-05 12:36:54 +08:00
|
|
|
return oss.str().substr(0, oss.str().length() - strlen(spdlog::details::os::default_eol));
|
2015-05-16 01:30:37 +08:00
|
|
|
}
|
|
|
|
|
2015-05-16 02:45:10 +08:00
|
|
|
TEST_CASE("basic_logging ", "[basic_logging]")
|
|
|
|
{
|
2015-05-16 01:30:37 +08:00
|
|
|
//const char
|
|
|
|
REQUIRE(log_info("Hello") == "Hello");
|
|
|
|
REQUIRE(log_info("") == "");
|
|
|
|
|
|
|
|
//std::string
|
|
|
|
REQUIRE(log_info(std::string("Hello")) == "Hello");
|
|
|
|
REQUIRE(log_info(std::string()) == std::string());
|
|
|
|
|
|
|
|
//Numbers
|
|
|
|
REQUIRE(log_info(5) == "5");
|
|
|
|
REQUIRE(log_info(5.6) == "5.6");
|
|
|
|
|
|
|
|
//User defined class
|
2016-07-03 08:43:55 +08:00
|
|
|
//REQUIRE(log_info(some_logged_class("some_val")) == "some_val");
|
2015-05-16 01:30:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("log_levels", "[log_levels]")
|
|
|
|
{
|
|
|
|
REQUIRE(log_info("Hello", spdlog::level::err) == "");
|
2016-07-09 06:00:16 +08:00
|
|
|
REQUIRE(log_info("Hello", spdlog::level::critical) == "");
|
2015-05-16 01:30:37 +08:00
|
|
|
REQUIRE(log_info("Hello", spdlog::level::info) == "Hello");
|
|
|
|
REQUIRE(log_info("Hello", spdlog::level::debug) == "Hello");
|
|
|
|
REQUIRE(log_info("Hello", spdlog::level::trace) == "Hello");
|
|
|
|
}
|
|
|
|
|
2018-03-09 06:08:24 +08:00
|
|
|
TEST_CASE("to_str", "[convert_to_str]")
|
|
|
|
{
|
|
|
|
REQUIRE(std::string(spdlog::level::to_str(spdlog::level::trace)) == "trace");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_str(spdlog::level::debug)) == "debug");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_str(spdlog::level::info)) == "info");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_str(spdlog::level::warn)) == "warning");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_str(spdlog::level::err)) == "error");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_str(spdlog::level::critical)) == "critical");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_str(spdlog::level::off)) == "off");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("to_short_str", "[convert_to_short_str]")
|
|
|
|
{
|
|
|
|
REQUIRE(std::string(spdlog::level::to_short_str(spdlog::level::trace)) == "T");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_short_str(spdlog::level::debug)) == "D");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_short_str(spdlog::level::info)) == "I");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_short_str(spdlog::level::warn)) == "W");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_short_str(spdlog::level::err)) == "E");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_short_str(spdlog::level::critical)) == "C");
|
|
|
|
REQUIRE(std::string(spdlog::level::to_short_str(spdlog::level::off)) == "O");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("to_level_enum", "[convert_to_level_enum]")
|
|
|
|
{
|
|
|
|
REQUIRE(spdlog::level::to_level_enum("trace") == spdlog::level::trace);
|
|
|
|
REQUIRE(spdlog::level::to_level_enum("debug") == spdlog::level::debug);
|
|
|
|
REQUIRE(spdlog::level::to_level_enum("info") == spdlog::level::info);
|
|
|
|
REQUIRE(spdlog::level::to_level_enum("warning") == spdlog::level::warn);
|
|
|
|
REQUIRE(spdlog::level::to_level_enum("error") == spdlog::level::err);
|
|
|
|
REQUIRE(spdlog::level::to_level_enum("critical") == spdlog::level::critical);
|
|
|
|
REQUIRE(spdlog::level::to_level_enum("off") == spdlog::level::off);
|
|
|
|
REQUIRE(spdlog::level::to_level_enum("null") == spdlog::level::off);
|
|
|
|
}
|
2015-05-16 01:30:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-23 22:40:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|