mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-30 01:04:05 +08:00
83c9ede9e6
Some checks failed
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[asan:ON build_type:Debug … (push) Has been cancelled
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Debug compiler… (push) Has been cancelled
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Release compil… (push) Has been cancelled
macos / macOS Clang (C++17, Release) (push) Has been cancelled
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Has been cancelled
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Has been cancelled
windows / build (map[BUILD_EXAMPLE:ON BUILD_SHARED:OFF BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Has been cancelled
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Has been cancelled
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Has been cancelled
Replace async logger with async sink
72 lines
2.3 KiB
C++
72 lines
2.3 KiB
C++
#include "includes.h"
|
|
#include "spdlog/sinks/ringbuffer_sink.h"
|
|
|
|
TEST_CASE("test_drain", "[ringbuffer_sink]") {
|
|
const size_t sink_size = 3;
|
|
auto sink = std::make_shared<spdlog::sinks::ringbuffer_sink_mt>(sink_size);
|
|
spdlog::logger l("logger", sink);
|
|
l.set_pattern("*** %v");
|
|
|
|
// log more than the sink size by one and test that the first message is dropped
|
|
// test 3 times to make sure the ringbuffer is working correctly multiple times
|
|
for (int i = 0; i < 3; i++) {
|
|
for (size_t i = 0; i < sink_size + 1; ++i) {
|
|
l.info("{}", i);
|
|
}
|
|
|
|
int counter = 0;
|
|
sink->drain([&](std::string_view msg) {
|
|
REQUIRE(msg == spdlog::fmt_lib::format("*** {}{}", counter + 1, spdlog::details::os::default_eol));
|
|
counter++;
|
|
});
|
|
|
|
REQUIRE(counter == sink_size);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("test_drain_raw", "[ringbuffer_sink]") {
|
|
const size_t sink_size = 3;
|
|
auto sink = std::make_shared<spdlog::sinks::ringbuffer_sink_mt>(sink_size);
|
|
spdlog::logger l("logger", sink);
|
|
|
|
// log more than the sink size by one and test that the first message is dropped
|
|
// test 3 times to make sure the ringbuffer is working correctly multiple times
|
|
for (int i = 0; i < 3; i++) {
|
|
for (size_t i = 0; i < sink_size + 1; ++i) {
|
|
l.info("{}", i);
|
|
}
|
|
|
|
int counter = 0;
|
|
sink->drain_raw([&](const spdlog::details::async_log_msg &buffer) {
|
|
REQUIRE(buffer.payload.data() == std::to_string(counter + 1));
|
|
counter++;
|
|
});
|
|
|
|
REQUIRE(counter == sink_size);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("test_empty", "[ringbuffer_sink]") {
|
|
const size_t sink_size = 3;
|
|
auto sink = std::make_shared<spdlog::sinks::ringbuffer_sink_mt>(sink_size);
|
|
spdlog::logger l("logger", sink);
|
|
|
|
sink->drain([&](std::string_view) {
|
|
REQUIRE_FALSE(true); // should not be called since the sink is empty
|
|
});
|
|
}
|
|
|
|
TEST_CASE("test_empty_size", "[ringbuffer_sink]") {
|
|
const size_t sink_size = 0;
|
|
auto sink = std::make_shared<spdlog::sinks::ringbuffer_sink_mt>(sink_size);
|
|
spdlog::logger l("logger", sink);
|
|
|
|
for (size_t i = 0; i < sink_size + 1; ++i) {
|
|
l.info("{}", i);
|
|
}
|
|
|
|
sink->drain([&](std::string_view) {
|
|
REQUIRE_FALSE(true); // should not be called since the sink size is 0
|
|
});
|
|
}
|