X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fformat.hpp;h=c1ab3d54ddc33cad2fb4a2b1c91aeab7ae2338dc;hb=32670d719327feb585374283a50eeb76ce36b962;hp=67509c275bad365ee23c2bd86ec7ab6fe44df5aa;hpb=31375c424ac115fc0373237207fed795849e26ba;p=lttng-tools.git diff --git a/src/common/format.hpp b/src/common/format.hpp index 67509c275..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 @@ -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 */