X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Ferror.hpp;h=fdae1e72c293bb0aefc16b008621dfb772993033;hp=7ce643411c8fd7567fd53e0dab26a1c87866b6c8;hb=HEAD;hpb=1944cedb180887d9dfe0906f930df167e714af99 diff --git a/src/common/error.hpp b/src/common/error.hpp index 7ce643411..23d840c2d 100644 --- a/src/common/error.hpp +++ b/src/common/error.hpp @@ -46,7 +46,8 @@ struct log_time { /* Format: 00:00:00.000000000 plus NULL byte. */ char str[19]; }; -extern DECLARE_URCU_TLS(const char *, logger_thread_name); + +extern thread_local const char *logger_thread_name; extern int lttng_opt_quiet; extern int lttng_opt_verbose; @@ -159,7 +160,7 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) msg " - %s [%s]: " fmt " (in %s() at " __FILE__ \ ":" XSTR(__LINE__) ")\n", \ log_add_time(), \ - URCU_TLS(logger_thread_name) ?: generic_name, \ + logger_thread_name ?: generic_name, \ ##args, \ __func__); \ } \ @@ -179,7 +180,7 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) __lttng_print(type, \ msg " - %s [%s]: " fmt "\n", \ log_add_time(), \ - URCU_TLS(logger_thread_name) ?: generic_name, \ + logger_thread_name ?: generic_name, \ ##args); \ } \ } while (0) @@ -251,12 +252,47 @@ 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()) - const char *error_get_str(int32_t code); +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 */ + +#define DBG_FMT(format_str, args...) \ + do { \ + try { \ + DBG("%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 WARN_FMT(format_str, args...) \ + do { \ + try { \ + WARN("%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 ERR_FMT(format_str, args...) \ + do { \ + try { \ + ERR("%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