mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-28 17:19:34 +08:00
V2.x no std format (#3271)
* Removed SPDLOG_USE_STD_FORMAT * Removed SPDLOG_USE_STD_FORMAT * clang-format * Fix windows.yml ci * Fix ci
This commit is contained in:
@@ -9,4 +9,4 @@ if(NOT TARGET spdlog)
|
||||
endif()
|
||||
|
||||
add_executable(example example.cpp)
|
||||
target_link_libraries(example PRIVATE spdlog::spdlog $<$<BOOL:${MINGW}>:ws2_32>)
|
||||
target_link_libraries(example PRIVATE spdlog::spdlog $<$<BOOL:${MINGW}>:ws2_32>)
|
||||
|
@@ -161,8 +161,7 @@ void async_example() {
|
||||
// {:p} - don't print the position on each line start.
|
||||
// {:n} - don't split the output to lines.
|
||||
|
||||
#if !defined SPDLOG_USE_STD_FORMAT || defined(_MSC_VER)
|
||||
#include "spdlog/fmt/bin_to_hex.h"
|
||||
#include "spdlog/fmt/bin_to_hex.h"
|
||||
void binary_example() {
|
||||
std::vector<char> buf;
|
||||
for (int i = 0; i < 80; i++) {
|
||||
@@ -177,26 +176,14 @@ void binary_example() {
|
||||
// logger->info("hexdump style: {:a}", spdlog::to_hex(buf));
|
||||
// logger->info("hexdump style, 20 chars per line {:a}", spdlog::to_hex(buf, 20));
|
||||
}
|
||||
#else
|
||||
void binary_example() {
|
||||
// not supported with std::format yet
|
||||
}
|
||||
#endif
|
||||
|
||||
// Log a vector of numbers
|
||||
#ifndef SPDLOG_USE_STD_FORMAT
|
||||
#include "fmt/ranges.h"
|
||||
#include "fmt/ranges.h"
|
||||
void vector_example() {
|
||||
std::vector<int> vec = {1, 2, 3};
|
||||
spdlog::info("Vector example: {}", vec);
|
||||
}
|
||||
|
||||
#else
|
||||
void vector_example() {}
|
||||
#endif
|
||||
|
||||
// ! DSPDLOG_USE_STD_FORMAT
|
||||
|
||||
// Compile time log levels.
|
||||
// define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE)
|
||||
void trace_example() {
|
||||
@@ -250,7 +237,6 @@ struct my_type {
|
||||
: i(i) {}
|
||||
};
|
||||
|
||||
#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib
|
||||
template <>
|
||||
struct fmt::formatter<my_type> : fmt::formatter<std::string> {
|
||||
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) {
|
||||
@@ -258,15 +244,6 @@ struct fmt::formatter<my_type> : fmt::formatter<std::string> {
|
||||
}
|
||||
};
|
||||
|
||||
#else // when using std::format
|
||||
template <>
|
||||
struct std::formatter<my_type> : std::formatter<std::string> {
|
||||
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) {
|
||||
return format_to(ctx.out(), "[my_type i={}]", my.i);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
void user_defined_example() { spdlog::info("user defined type: {}", my_type(14)); }
|
||||
|
||||
// Custom error handler. Will be triggered on log failure.
|
||||
|
Reference in New Issue
Block a user