X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fformat.hpp;h=c1ab3d54ddc33cad2fb4a2b1c91aeab7ae2338dc;hb=513792873b851baef066648b41f9cbfe978063fc;hp=020766eb5ddd788dfd7c8114a6bd993e7817cfdf;hpb=11bcbf894cf92b99a2d885cad117db6811f164cb;p=lttng-tools.git diff --git a/src/common/format.hpp b/src/common/format.hpp index 020766eb5..c1ab3d54d 100644 --- a/src/common/format.hpp +++ b/src/common/format.hpp @@ -9,8 +9,9 @@ #include -#include #include +#include +#include DIAGNOSTIC_PUSH DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT @@ -26,11 +27,13 @@ DIAGNOSTIC_POP namespace fmt { template <> struct formatter : formatter { - template - typename FormatCtx::iterator format(const std::type_info& type_info, FormatCtx& ctx) + template + typename FormatContextType::iterator format(const std::type_info& type_info, + FormatContextType& ctx) { int status; - auto demangled_name = abi::__cxa_demangle(type_info.name(), nullptr, 0, &status); + auto demangled_name = + abi::__cxa_demangle(type_info.name(), nullptr, nullptr, &status); auto it = status == 0 ? formatter::format(demangled_name, ctx) : formatter::format(type_info.name(), ctx); @@ -40,4 +43,16 @@ struct formatter : formatter { }; } /* namespace fmt */ +namespace lttng { +template +std::string format(FormattingArguments&&...args) +{ + try { + return fmt::format(std::forward(args)...); + } catch (const fmt::format_error& ex) { + return std::string("Failed to format string: ") += ex.what(); + } +} +} /* namespace lttng */ + #endif /* LTTNG_FORMAT_H */