diff --git a/include/luisa/core/logging.h b/include/luisa/core/logging.h index c2ad9a2b5..d5f5ba08f 100644 --- a/include/luisa/core/logging.h +++ b/include/luisa/core/logging.h @@ -66,10 +66,8 @@ template auto trace = luisa::backtrace(); for (auto i = 0u; i < trace.size(); i++) { auto &&t = trace[i]; - using namespace std::string_view_literals; - error_message.append(luisa::format( - ("\n {:>2} {}"sv), - i, luisa::to_string(t))); + fmt::format_to(std::back_inserter(error_message), + FMT_STRING("\n {:>2} {}"), i, t); } detail::default_logger().error(error_message); std::abort(); @@ -89,33 +87,27 @@ LC_CORE_API void log_flush() noexcept; }// namespace luisa -#ifdef LUISA_DISABLE_STATIC_FMT_STRING -#define LUISA_STATIC_FMT_STRING(s) (s) -#else -#define LUISA_STATIC_FMT_STRING(s) FMT_STRING(s) -#endif - /** * @brief Verbose logging * * Ex. LUISA_VERBOSE("function {} returns {}", functionName, functionReturnInt); */ #define LUISA_VERBOSE(f, ...) \ - ::luisa::log_verbose(::fmt::format(LUISA_STATIC_FMT_STRING(f) __VA_OPT__(, ) __VA_ARGS__)) + ::luisa::log_verbose(::fmt::format(FMT_STRING(f) __VA_OPT__(, ) __VA_ARGS__)) /** * @brief Info logging * * Ex. LUISA_INFO("function {} returns {}", functionName, functionReturnInt); */ #define LUISA_INFO(f, ...) \ - ::luisa::log_info(::fmt::format(LUISA_STATIC_FMT_STRING(f) __VA_OPT__(, ) __VA_ARGS__)) + ::luisa::log_info(::fmt::format(FMT_STRING(f) __VA_OPT__(, ) __VA_ARGS__)) /** * @brief Warning logging * * Ex. LUISA_WARNING("function {} returns {}", functionName, functionReturnInt); */ #define LUISA_WARNING(f, ...) \ - ::luisa::log_warning(::fmt::format(LUISA_STATIC_FMT_STRING(f) __VA_OPT__(, ) __VA_ARGS__)) + ::luisa::log_warning(::fmt::format(FMT_STRING(f) __VA_OPT__(, ) __VA_ARGS__)) /** * @brief Error logging * @@ -123,7 +115,7 @@ LC_CORE_API void log_flush() noexcept; * Ex. LUISA_ERROR("function {} returns {}", functionName, functionReturnInt); */ #define LUISA_ERROR(f, ...) \ - ::luisa::log_error(::fmt::format(LUISA_STATIC_FMT_STRING(f) __VA_OPT__(, ) __VA_ARGS__)) + ::luisa::log_error(::fmt::format(FMT_STRING(f) __VA_OPT__(, ) __VA_ARGS__)) /// LUISA_VERBOSE with file and line information #define LUISA_VERBOSE_WITH_LOCATION(fmt, ...) \ diff --git a/include/luisa/core/stl/format.h b/include/luisa/core/stl/format.h index 54465f2a1..aff163d11 100644 --- a/include/luisa/core/stl/format.h +++ b/include/luisa/core/stl/format.h @@ -12,6 +12,7 @@ #include #include +#include // for TraceItem namespace luisa { @@ -45,11 +46,11 @@ namespace fmt { template struct formatter> { - constexpr auto parse(format_parse_context &ctx) const -> decltype(ctx.begin()) { + constexpr auto parse(format_parse_context &ctx) const noexcept { return ctx.end(); } template - auto format(const luisa::Vector &v, FormatContext &ctx) const -> decltype(ctx.out()) { + auto format(const luisa::Vector &v, FormatContext &ctx) const noexcept { using namespace std::string_view_literals; using luisa::uint; using luisa::ushort; @@ -91,11 +92,11 @@ struct formatter> { template struct formatter> { - constexpr auto parse(format_parse_context &ctx) const -> decltype(ctx.begin()) { + constexpr auto parse(format_parse_context &ctx) const noexcept { return ctx.end(); } template - auto format(const luisa::Matrix &m, FormatContext &ctx) const -> decltype(ctx.out()) { + auto format(const luisa::Matrix &m, FormatContext &ctx) const noexcept { if constexpr (N == 2u) { return fmt::format_to( ctx.out(), @@ -132,16 +133,17 @@ struct formatter> { } }; -// template -// struct formatter> { -// constexpr auto parse(format_parse_context &ctx) const -> decltype(ctx.begin()) { -// return ctx.end(); -// } -// template -// auto format(const std::array &a, FormatContext &ctx) const -> decltype(ctx.out()) { -// return fmt::format_to(ctx.out(), FMT_STRING("[{}]"), fmt::join(a, ", ")); -// } -// }; +template<> +struct formatter { + constexpr auto parse(format_parse_context &ctx) const noexcept { + return ctx.end(); + } + template + auto format(const luisa::TraceItem &item, FormatContext &ctx) const noexcept { + return luisa::format_to(ctx.out(), FMT_STRING("[0x{:012x}]: {} :: {} + {}"), + item.address, item.module, item.symbol, item.offset); + } +}; }// namespace fmt diff --git a/src/core/platform.cpp b/src/core/platform.cpp index 088e4fbbb..89d8f6b7e 100644 --- a/src/core/platform.cpp +++ b/src/core/platform.cpp @@ -392,8 +392,6 @@ luisa::string current_executable_path() noexcept { namespace luisa { luisa::string to_string(const TraceItem &item) noexcept { using namespace std::string_view_literals; - return luisa::format( - FMT_STRING("[0x{:012x}]: {} :: {} + {}"sv), - item.address, item.module, item.symbol, item.offset); + return luisa::format("{}", item); } }// namespace luisa