mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-26 10:31:34 +08:00
166843ff3a
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
Removed registry
52 lines
1.7 KiB
C++
52 lines
1.7 KiB
C++
/*
|
|
* This content is released under the MIT License as specified in
|
|
* https://raw.githubusercontent.com/gabime/spdlog/v2.x/LICENSE
|
|
*/
|
|
|
|
#include "includes.h"
|
|
#include "spdlog/sinks/basic_file_sink.h"
|
|
|
|
#if SPDLOG_ACTIVE_LEVEL != SPDLOG_LEVEL_DEBUG
|
|
#error "Invalid SPDLOG_ACTIVE_LEVEL in test. Should be SPDLOG_LEVEL_DEBUG"
|
|
#endif
|
|
|
|
#define TEST_FILENAME "test_logs/simple_log"
|
|
|
|
TEST_CASE("debug and trace w/o format string", "[macros]") {
|
|
prepare_logdir();
|
|
spdlog::filename_t filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
|
auto logger = spdlog::basic_logger_mt("logger", filename);
|
|
logger->set_pattern("%v");
|
|
logger->set_level(spdlog::level::trace);
|
|
|
|
SPDLOG_LOGGER_TRACE(logger, "Test message 1");
|
|
SPDLOG_LOGGER_DEBUG(logger, "Test message 2");
|
|
logger->flush();
|
|
|
|
using spdlog::details::os::default_eol;
|
|
REQUIRE(ends_with(file_contents(TEST_FILENAME), spdlog::fmt_lib::format("Test message 2{}", default_eol)));
|
|
REQUIRE(count_lines(TEST_FILENAME) == 1);
|
|
|
|
auto orig_global_logger = spdlog::global_logger();
|
|
spdlog::set_global_logger(logger);
|
|
|
|
SPDLOG_TRACE("Test message 3");
|
|
SPDLOG_DEBUG("Test message {}", 4);
|
|
logger->flush();
|
|
|
|
require_message_count(TEST_FILENAME, 2);
|
|
REQUIRE(ends_with(file_contents(TEST_FILENAME), spdlog::fmt_lib::format("Test message 4{}", default_eol)));
|
|
spdlog::set_global_logger(std::move(orig_global_logger));
|
|
}
|
|
|
|
TEST_CASE("disable param evaluation", "[macros]") {
|
|
SPDLOG_TRACE("Test message {}", throw std::runtime_error("Should not be evaluated"));
|
|
}
|
|
|
|
TEST_CASE("pass logger pointer", "[macros]") {
|
|
auto logger = spdlog::null_logger_mt("refmacro");
|
|
auto &ref = *logger;
|
|
SPDLOG_LOGGER_TRACE(&ref, "Test message 1");
|
|
SPDLOG_LOGGER_DEBUG(&ref, "Test message 2");
|
|
}
|