1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-04-01 02:42:41 +08:00

Fixed example for std_format

This commit is contained in:
gabime 2021-12-04 14:32:01 +02:00
parent e3e4c4bc95
commit 5bf8728cfa

View File

@ -191,7 +191,7 @@ void binary_example()
} }
// Log a vector of numbers // Log a vector of numbers
#ifndef SPDLOG_USE_STD_FORMAT
# include "spdlog/fmt/bundled/ranges.h" # include "spdlog/fmt/bundled/ranges.h"
void vector_example() void vector_example()
{ {
@ -199,6 +199,12 @@ void vector_example()
spdlog::info("Vector example: {}", vec); spdlog::info("Vector example: {}", vec);
} }
#else
void vector_example() {}
#endif
// ! DSPDLOG_USE_STD_FORMAT
// Compile time log levels. // Compile time log levels.
// define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE) // define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE)
void trace_example() void trace_example()
@ -252,10 +258,14 @@ void multi_sink_example()
struct my_type struct my_type
{ {
int i; int i;
template<typename OStream> };
friend OStream &operator<<(OStream &os, const my_type &c)
template<>
struct std::formatter<my_type> : std::formatter<std::string>
{ {
return os << "[my_type i=" << c.i << "]"; auto format(my_type my, format_context &ctx)
{
return formatter<string>::format(std::format("[my_type i={}]", my.i), ctx);
} }
}; };
@ -354,4 +364,3 @@ void replace_default_logger_example()
spdlog::set_default_logger(old_logger); spdlog::set_default_logger(old_logger);
} }