From b89fd4a2af6c94d27e652fd20310da0f8526abbf Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Wed, 11 Dec 2024 10:53:59 -0500 Subject: [PATCH] error: Add `PWARN_FMT` and `PERROR_FMT` macros MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ib46fbed81c429f54793c9787a537950faa5552e0 Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau --- src/common/error.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/common/error.hpp b/src/common/error.hpp index 66f38bf2e..c78c492b8 100644 --- a/src/common/error.hpp +++ b/src/common/error.hpp @@ -308,6 +308,26 @@ namespace details { } \ } while (0); +#define PERROR_FMT(format_str, args...) \ + do { \ + try { \ + PERROR("%s", lttng::format(format_str, ##args).c_str()); \ + } catch (const std::exception& _formatting_exception) { \ + lttng::logging::details::die_formatting_exception(format_str, \ + _formatting_exception); \ + } \ + } while (0); + +#define PWARN_FMT(format_str, args...) \ + do { \ + try { \ + PWARN("%s", lttng::format(format_str, ##args).c_str()); \ + } catch (const std::exception& _formatting_exception) { \ + lttng::logging::details::die_formatting_exception(format_str, \ + _formatting_exception); \ + } \ + } while (0); + /* * Function that format the time and return the reference of log_time.str to * the caller. On error, an empty string is returned thus no time will be -- 2.39.5