mirror of
https://github.com/gabime/spdlog.git
synced 2025-03-04 13:15:48 +08:00

The logger interface should not be bloated by additional functionality. Reducing it to a nested call to `.attrs().put()` achieves the same nesting as `.put_attribute()` but requires a smaller interface change on the logger class.
26 lines
796 B
C++
26 lines
796 B
C++
#include "includes.h"
|
|
#include "spdlog/mdc.h"
|
|
#include "spdlog/sinks/stdout_sinks.h"
|
|
#include "spdlog/spdlog.h"
|
|
#include "test_sink.h"
|
|
|
|
TEST_CASE("Attribute test") {
|
|
auto test_sink = std::make_shared<spdlog::sinks::test_sink_st>();
|
|
spdlog::logger log_a("log_a", test_sink);
|
|
spdlog::logger log_b("log_b", test_sink);
|
|
log_a.set_pattern("[%n] [%*]");
|
|
log_b.set_pattern("[%n] [%*]");
|
|
|
|
log_a.attrs().put("my_key", "my_value");
|
|
|
|
log_a.info("Hello");
|
|
log_b.info("Hello");
|
|
|
|
auto expected_log_a = spdlog::fmt_lib::format("[log_a] [my_key:my_value]");
|
|
auto expected_log_b = spdlog::fmt_lib::format("[log_b] []");
|
|
|
|
auto lines = test_sink->lines();
|
|
REQUIRE(lines.size() == 2);
|
|
REQUIRE(lines[0] == expected_log_a);
|
|
REQUIRE(lines[1] == expected_log_b);
|
|
} |