X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fformat.hpp;h=c1ab3d54ddc33cad2fb4a2b1c91aeab7ae2338dc;hb=11927a7859022cf38a4153767cc96fda4987070d;hp=389bc596ad85787c7f00aa7506532f56898551cf;hpb=28f23191dcbf047429d51950a337a57d7a3f866a;p=lttng-tools.git diff --git a/src/common/format.hpp b/src/common/format.hpp index 389bc596a..c1ab3d54d 100644 --- a/src/common/format.hpp +++ b/src/common/format.hpp @@ -11,6 +11,7 @@ #include #include +#include DIAGNOSTIC_PUSH DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT @@ -42,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 */