mirror of
https://github.com/gabime/spdlog.git
synced 2025-03-31 10:22:41 +08:00
Fixed example for std_format
This commit is contained in:
parent
e3e4c4bc95
commit
5bf8728cfa
@ -191,14 +191,20 @@ 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()
|
||||||
{
|
{
|
||||||
std::vector<int> vec = {1, 2, 3};
|
std::vector<int> vec = {1, 2, 3};
|
||||||
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>
|
||||||
|
{
|
||||||
|
auto format(my_type my, format_context &ctx)
|
||||||
{
|
{
|
||||||
return os << "[my_type i=" << c.i << "]";
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user