X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Ferror.hpp;h=93616718f65dd89481492d39bf7ef0fe8ba1d261;hb=003f455dab0204dd3f066ecdbea0470035f8181f;hp=7ce643411c8fd7567fd53e0dab26a1c87866b6c8;hpb=1944cedb180887d9dfe0906f930df167e714af99;p=lttng-tools.git diff --git a/src/common/error.hpp b/src/common/error.hpp index 7ce643411..93616718f 100644 --- a/src/common/error.hpp +++ b/src/common/error.hpp @@ -242,6 +242,7 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) /* * Version using GNU strerror_r, for linux with appropriate defines. */ +const char *error_get_str(int32_t code); #define PERROR(call, args...) \ do { \ char *_perror_buf; \ @@ -251,11 +252,44 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) } while (0); #endif -#define DBG_FMT(format_str, args...) DBG("%s", fmt::format(format_str, ##args).c_str()) -#define WARN_FMT(format_str, args...) WARN("%s", fmt::format(format_str, ##args).c_str()) -#define ERR_FMT(format_str, args...) ERR("%s", fmt::format(format_str, ##args).c_str()) +namespace lttng { +namespace logging { +namespace details { +[[noreturn]] void die_formatting_exception(const char *format, + const std::exception& formatting_exception); +} /* namespace details */ +} /* namespace logging */ +} /* namespace lttng */ -const char *error_get_str(int32_t code); +#define DBG_FMT(format_str, args...) \ + do { \ + try { \ + DBG("%s", fmt::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 WARN_FMT(format_str, args...) \ + do { \ + try { \ + WARN("%s", fmt::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 ERR_FMT(format_str, args...) \ + do { \ + try { \ + ERR("%s", fmt::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