X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;ds=sidebyside;f=src%2Fcommon%2Fformat.hpp;h=c1ab3d54ddc33cad2fb4a2b1c91aeab7ae2338dc;hb=fe3442d8303182515a02153340291c9f020e24c3;hp=b586fd489f8f934f8ace25808c7e19ce2acd4fe9;hpb=cd9adb8b829564212158943a0d279bb35322ab30;p=lttng-tools.git diff --git a/src/common/format.hpp b/src/common/format.hpp index b586fd489..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,8 +27,9 @@ 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 = @@ -41,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 */