I'm using msvc, now I need a logger function that can:
- acquire the caller's name automatically
- can receive variadic args just like fmt::format or std::format
I tried the following:
- use macro, it works, but it's not easy to encapsulate into a class.
- use stacktrace library. these libraries requires pdb file but I just need embedded name strings.
- use , I tried to use both
Код: Выделить всё
std::source_location::current()and template argument packКод: Выделить всё
std::source_locationlike that:Код: Выделить всё
Args&&... args
Код: Выделить всё
#include #include #include template void log(const char* format_str, Args&&... args, const std::source_location& location = std::source_location::current()) { std::string func_name = location.function_name(); std::string message = std::format(format_str, std::forward(args)...); std::cout
Источник: [url]https://stackoverflow.com/questions/78132137/implement-variadic-log-function-that-acquire-callers-name-automatically[/url]