mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 01:29:35 +08:00
Added support for binary logging using to_hex(..)
This commit is contained in:
@@ -134,3 +134,46 @@ TEST_CASE("clone async", "[clone]")
|
||||
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "spdlog/fmt/bin_to_hex.h"
|
||||
|
||||
TEST_CASE("to_hex", "[to_hex]")
|
||||
{
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||
spdlog::logger oss_logger("oss", oss_sink);
|
||||
|
||||
std::vector<unsigned char> v {9, 0xa, 0xb, 0xc, 0xff, 0xff};
|
||||
oss_logger.info("{}", spdlog::to_hex(v));
|
||||
|
||||
auto output = oss.str();
|
||||
REQUIRE(ends_with(output, "0000: 09 0a 0b 0c ff ff" + std::string(spdlog::details::os::default_eol)));
|
||||
}
|
||||
|
||||
TEST_CASE("to_hex_upper", "[to_hex]")
|
||||
{
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||
spdlog::logger oss_logger("oss", oss_sink);
|
||||
|
||||
std::vector<unsigned char> v {9, 0xa, 0xb, 0xc, 0xff, 0xff};
|
||||
oss_logger.info("{:X}", spdlog::to_hex(v));
|
||||
|
||||
auto output = oss.str();
|
||||
REQUIRE(ends_with(output, "0000: 09 0A 0B 0C FF FF" + std::string(spdlog::details::os::default_eol)));
|
||||
}
|
||||
|
||||
TEST_CASE("to_hex_no_delimiter", "[to_hex]")
|
||||
{
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||
spdlog::logger oss_logger("oss", oss_sink);
|
||||
|
||||
std::vector<unsigned char> v {9, 0xa, 0xb, 0xc, 0xff, 0xff};
|
||||
oss_logger.info("{:sX}", spdlog::to_hex(v));
|
||||
|
||||
auto output = oss.str();
|
||||
REQUIRE(ends_with(output, "0000: 090A0B0CFFFF" + std::string(spdlog::details::os::default_eol)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user