Removed SPDLOG_USE_STD_FORMAT
This commit is contained in:
parent
d7c6cc13a5
commit
ea896885cd
2
.github/workflows/windows.yml
vendored
2
.github/workflows/windows.yml
vendored
@ -57,7 +57,6 @@ jobs:
|
|||||||
-D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} `
|
-D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} `
|
||||||
-D SPDLOG_BUILD_TESTS=ON `
|
-D SPDLOG_BUILD_TESTS=ON `
|
||||||
-D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} `
|
-D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} `
|
||||||
-D SPDLOG_USE_STD_FORMAT=${{ matrix.config.USE_STD_FORMAT }} `
|
|
||||||
-D CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} ..
|
-D CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} ..
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
@ -118,7 +117,6 @@ jobs:
|
|||||||
-D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} `
|
-D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} `
|
||||||
-D SPDLOG_BUILD_TESTS=ON `
|
-D SPDLOG_BUILD_TESTS=ON `
|
||||||
-D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} `
|
-D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} `
|
||||||
-D SPDLOG_USE_STD_FORMAT=${{ matrix.config.USE_STD_FORMAT }} `
|
|
||||||
-D CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} ..
|
-D CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} ..
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
|
@ -12,12 +12,7 @@
|
|||||||
#include "spdlog/sinks/rotating_file_sink.h"
|
#include "spdlog/sinks/rotating_file_sink.h"
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
#if defined(SPDLOG_USE_STD_FORMAT)
|
#include <fmt/format.h>
|
||||||
#include <format>
|
|
||||||
#else
|
|
||||||
#include <fmt/format.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstdlib> // EXIT_FAILURE
|
#include <cstdlib> // EXIT_FAILURE
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -7,10 +7,7 @@ include(CMakeFindDependencyMacro)
|
|||||||
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
set(SPDLOG_USE_STD_FORMAT @SPDLOG_USE_STD_FORMAT@)
|
find_dependency(fmt CONFIG)
|
||||||
if(NOT SPDLOG_USE_STD_FORMAT)
|
|
||||||
find_dependency(fmt CONFIG)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(config_targets_file @config_targets_file@)
|
set(config_targets_file @config_targets_file@)
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file}")
|
include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file}")
|
||||||
|
@ -27,9 +27,5 @@
|
|||||||
// Disable default logger creation
|
// Disable default logger creation
|
||||||
#cmakedefine SPDLOG_DISABLE_DEFAULT_LOGGER
|
#cmakedefine SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||||
|
|
||||||
// Use std::format instead of fmtlib
|
|
||||||
#cmakedefine SPDLOG_USE_STD_FORMAT
|
|
||||||
|
|
||||||
// Use external fmtlib instead of bundled
|
// Use external fmtlib instead of bundled
|
||||||
#cmakedefine SPDLOG_FMT_EXTERNAL
|
#cmakedefine SPDLOG_FMT_EXTERNAL
|
||||||
|
|
||||||
|
@ -26,13 +26,9 @@ spdlog_ex::spdlog_ex(std::string msg)
|
|||||||
: msg_(std::move(msg)) {}
|
: msg_(std::move(msg)) {}
|
||||||
|
|
||||||
spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) {
|
spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) {
|
||||||
#ifdef SPDLOG_USE_STD_FORMAT
|
|
||||||
msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what();
|
|
||||||
#else
|
|
||||||
memory_buf_t outbuf;
|
memory_buf_t outbuf;
|
||||||
fmt::format_system_error(outbuf, last_errno, msg.c_str());
|
fmt::format_system_error(outbuf, last_errno, msg.c_str());
|
||||||
msg_ = fmt::to_string(outbuf);
|
msg_ = fmt::to_string(outbuf);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *spdlog_ex::what() const noexcept { return msg_.c_str(); }
|
const char *spdlog_ex::what() const noexcept { return msg_.c_str(); }
|
||||||
|
@ -52,7 +52,8 @@ set(SPDLOG_UTESTS_SOURCES
|
|||||||
test_source_location.cpp
|
test_source_location.cpp
|
||||||
test_no_source_location.cpp
|
test_no_source_location.cpp
|
||||||
test_log_level.cpp
|
test_log_level.cpp
|
||||||
test_include_sinks.cpp)
|
test_include_sinks.cpp
|
||||||
|
test_bin_to_hex.cpp)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
list(APPEND SPDLOG_UTESTS_SOURCES test_eventlog.cpp)
|
list(APPEND SPDLOG_UTESTS_SOURCES test_eventlog.cpp)
|
||||||
@ -66,10 +67,6 @@ if(systemd_FOUND)
|
|||||||
list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp)
|
list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT SPDLOG_USE_STD_FORMAT)
|
|
||||||
list(APPEND SPDLOG_UTESTS_SOURCES test_bin_to_hex.cpp)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
function(spdlog_prepare_test test_target spdlog_lib)
|
function(spdlog_prepare_test test_target spdlog_lib)
|
||||||
|
@ -6,11 +6,7 @@
|
|||||||
#include "spdlog/sinks/daily_file_sink.h"
|
#include "spdlog/sinks/daily_file_sink.h"
|
||||||
#include "spdlog/sinks/rotating_file_sink.h"
|
#include "spdlog/sinks/rotating_file_sink.h"
|
||||||
|
|
||||||
#ifdef SPDLOG_USE_STD_FORMAT
|
using filename_memory_buf_t = spdlog::memory_buf_t;
|
||||||
using filename_memory_buf_t = std::basic_string<spdlog::filename_t::value_type>;
|
|
||||||
#else
|
|
||||||
using filename_memory_buf_t = fmt::basic_memory_buffer<spdlog::filename_t::value_type, 250>;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SPDLOG_WCHAR_FILENAMES
|
#ifdef SPDLOG_WCHAR_FILENAMES
|
||||||
std::string filename_buf_to_utf8string(const filename_memory_buf_t &w) {
|
std::string filename_buf_to_utf8string(const filename_memory_buf_t &w) {
|
||||||
|
@ -18,7 +18,7 @@ protected:
|
|||||||
};
|
};
|
||||||
struct custom_ex {};
|
struct custom_ex {};
|
||||||
|
|
||||||
#if !defined(SPDLOG_USE_STD_FORMAT) // std formt doesn't fully support runtime format strings
|
|
||||||
TEST_CASE("default_error_handler", "[errors]") {
|
TEST_CASE("default_error_handler", "[errors]") {
|
||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
|
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
|
||||||
@ -45,7 +45,6 @@ TEST_CASE("custom_error_handler", "[errors]") {
|
|||||||
logger->info("Good message #2");
|
logger->info("Good message #2");
|
||||||
require_message_count(SIMPLE_LOG, 2);
|
require_message_count(SIMPLE_LOG, 2);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
TEST_CASE("default_error_handler2", "[errors]") {
|
TEST_CASE("default_error_handler2", "[errors]") {
|
||||||
spdlog::drop_all();
|
spdlog::drop_all();
|
||||||
@ -61,7 +60,6 @@ TEST_CASE("flush_error_handler", "[errors]") {
|
|||||||
REQUIRE_THROWS_AS(logger->flush(), custom_ex);
|
REQUIRE_THROWS_AS(logger->flush(), custom_ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(SPDLOG_USE_STD_FORMAT) // std formt doesn't fully support runtime format strings
|
|
||||||
TEST_CASE("async_error_handler", "[errors]") {
|
TEST_CASE("async_error_handler", "[errors]") {
|
||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
std::string err_msg("log failed with some msg");
|
std::string err_msg("log failed with some msg");
|
||||||
@ -86,7 +84,6 @@ TEST_CASE("async_error_handler", "[errors]") {
|
|||||||
require_message_count(SIMPLE_ASYNC_LOG, 2);
|
require_message_count(SIMPLE_ASYNC_LOG, 2);
|
||||||
REQUIRE(file_contents("test_logs/custom_err.txt") == err_msg);
|
REQUIRE(file_contents("test_logs/custom_err.txt") == err_msg);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Make sure async error handler is executed
|
// Make sure async error handler is executed
|
||||||
TEST_CASE("async_error_handler2", "[errors]") {
|
TEST_CASE("async_error_handler2", "[errors]") {
|
||||||
|
Loading…
Reference in New Issue
Block a user