Skip to content

Instantly share code, notes, and snippets.

@WiwilZ
Created November 27, 2025 07:08
Show Gist options
  • Select an option

  • Save WiwilZ/cfff4cd0fdf39b7cb6fc49a227c079dd to your computer and use it in GitHub Desktop.

Select an option

Save WiwilZ/cfff4cd0fdf39b7cb6fc49a227c079dd to your computer and use it in GitHub Desktop.
namespace Logger {
struct FormatWithLocation {
std::string_view str;
std::source_location loc;
template <typename String>
FormatWithLocation(const String& str, const std::source_location& loc = std::source_location::current()): str(str), loc(loc) {}
template <typename...Args>
void Debug(FormatWithLocation fmt, Args &&...args) {
std::string formattedMessage = std::vformat(fmt.value, std::make_format_args(std::forward<Args>(args)...));
std::cout << std::format("[{}:{}] {}\n", fmt.loc.file_name(), fmt.loc.line(), formattedMessage);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment