From: Simon Marchi Date: Thu, 4 Apr 2024 02:29:21 +0000 (-0400) Subject: cpp-common/bt2c: Logger: remove `noThrow` suffixes X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=9d15c577f01657e81be83b054f5edb218b0d6552 cpp-common/bt2c: Logger: remove `noThrow` suffixes I think that the `noThrow` suffixes are unnecessary. Since the methods that throw (or rethrow) have the `AndThrow` (or `AndRethrow`) suffixes, it is implied that those that don't, don't. Simplify some macro comments to omit "without appending nor throwing", for the same reason (if the macro name doesn't contain "APPEND_CAUSE", it doesn't append a cause, if it doesn't contain "THROW", it doesn't throw). Change-Id: Ia71cf733e857e89578648eda12bf64b2bfc65027 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/12229 Reviewed-by: Philippe Proulx Tested-by: jenkins --- diff --git a/src/cpp-common/bt2c/logging.hpp b/src/cpp-common/bt2c/logging.hpp index 86258770..9d72f3dc 100644 --- a/src/cpp-common/bt2c/logging.hpp +++ b/src/cpp-common/bt2c/logging.hpp @@ -32,9 +32,9 @@ namespace bt2c { * self message iterator, or simple module name), a current logging * level, and a logging tag. * - * It offers the logNoThrow(), logMemNoThrow(), logErrnoNoThrow(), - * logErrorAndThrow(), logErrorAndRethrow(), logErrorErrnoAndThrow(), - * and logErrorErrnoAndRethrow() method templates to log using a given + * It offers the log(), logMem(), logErrno(), logErrorAndThrow(), + * logErrorAndRethrow(), logErrorErrnoAndThrow(), and + * logErrorErrnoAndRethrow() method templates to log using a given * level, optionally append a cause to the error of the current thread * using the correct actor, and optionally throw or rethrow. * @@ -278,11 +278,11 @@ public: * the error of the current thread using the same message. */ template - void logNoThrow(const char * const fileName, const char * const funcName, - const unsigned int lineNo, const char * const fmt, ArgTs&&...args) const + void log(const char * const fileName, const char * const funcName, const unsigned int lineNo, + const char * const fmt, ArgTs&&...args) const { - this->_logNoThrow<_StdLogWriter, LevelV, AppendCauseV>( - fileName, funcName, lineNo, nullptr, 0, "", fmt, std::forward(args)...); + this->_log<_StdLogWriter, LevelV, AppendCauseV>(fileName, funcName, lineNo, nullptr, 0, "", + fmt, std::forward(args)...); } /* @@ -292,63 +292,61 @@ public: * the error of the current thread using the same message. */ template - void logStrNoThrow(const char * const fileName, const char * const funcName, - const unsigned int lineNo, const char * const msg) const + void logStr(const char * const fileName, const char * const funcName, const unsigned int lineNo, + const char * const msg) const { - this->_logStrNoThrow<_StdLogWriter, LevelV, AppendCauseV>(fileName, funcName, lineNo, - nullptr, 0, "", msg); + this->_logStr<_StdLogWriter, LevelV, AppendCauseV>(fileName, funcName, lineNo, nullptr, 0, + "", msg); } /* - * Like logNoThrow() with the `Level::Error` level, but also - * throws a default-constructed instance of `ExcT`. + * Like log() with the `Level::Error` level, but also throws a + * default-constructed instance of `ExcT`. */ template [[noreturn]] void logErrorAndThrow(const char * const fileName, const char * const funcName, const unsigned int lineNo, const char * const fmt, ArgTs&&...args) const { - this->logNoThrow(fileName, funcName, lineNo, fmt, - std::forward(args)...); + this->log(fileName, funcName, lineNo, fmt, + std::forward(args)...); throw ExcT {}; } /* - * Like logStrNoThrow() with the `Level::Error` level, but also - * throws a default-constructed instance of `ExcT`. + * Like logStr() with the `Level::Error` level, but also throws a + * default-constructed instance of `ExcT`. */ template [[noreturn]] void logErrorStrAndThrow(const char * const fileName, const char * const funcName, const unsigned int lineNo, const char * const msg) const { - this->logStrNoThrow(fileName, funcName, lineNo, msg); + this->logStr(fileName, funcName, lineNo, msg); throw ExcT {}; } /* - * Like logNoThrow() with the `Level::Error` level, but also - * rethrows. + * Like log() with the `Level::Error` level, but also rethrows. */ template [[noreturn]] void logErrorAndRethrow(const char * const fileName, const char * const funcName, const unsigned int lineNo, const char * const fmt, ArgTs&&...args) const { - this->logNoThrow(fileName, funcName, lineNo, fmt, - std::forward(args)...); + this->log(fileName, funcName, lineNo, fmt, + std::forward(args)...); throw; } /* - * Like logStrNoThrow() with the `Level::Error` level, but also - * rethrows. + * Like logStr() with the `Level::Error` level, but also rethrows. */ template [[noreturn]] void logErrorStrAndRethrow(const char * const fileName, const char * const funcName, const unsigned int lineNo, const char * const msg) const { - this->logStrNoThrow(fileName, funcName, lineNo, msg); + this->logStr(fileName, funcName, lineNo, msg); throw; } @@ -377,13 +375,13 @@ public: * the error of the current thread using the same message. */ template - void logErrnoNoThrow(const char * const fileName, const char * const funcName, - const unsigned int lineNo, const char * const initMsg, - const char * const fmt, ArgTs&&...args) const + void logErrno(const char * const fileName, const char * const funcName, + const unsigned int lineNo, const char * const initMsg, const char * const fmt, + ArgTs&&...args) const { - this->_logNoThrow<_InitMsgLogWriter, LevelV, AppendCauseV>( - fileName, funcName, lineNo, nullptr, 0, this->_errnoIntroStr(initMsg).c_str(), fmt, - std::forward(args)...); + this->_log<_InitMsgLogWriter, LevelV, AppendCauseV>(fileName, funcName, lineNo, nullptr, 0, + this->_errnoIntroStr(initMsg).c_str(), + fmt, std::forward(args)...); } /* @@ -396,17 +394,17 @@ public: * the error of the current thread using the same message. */ template - void logErrnoStrNoThrow(const char * const fileName, const char * const funcName, - const unsigned int lineNo, const char * const initMsg, - const char * const msg) const + void logErrnoStr(const char * const fileName, const char * const funcName, + const unsigned int lineNo, const char * const initMsg, + const char * const msg) const { - this->_logStrNoThrow<_InitMsgLogWriter, LevelV, AppendCauseV>( + this->_logStr<_InitMsgLogWriter, LevelV, AppendCauseV>( fileName, funcName, lineNo, nullptr, 0, this->_errnoIntroStr(initMsg).c_str(), msg); } /* - * Like logErrnoNoThrow() with the `Level::Error` level, but also - * throws a default-constructed instance of `ExcT`. + * Like logErrno() with the `Level::Error` level, but also throws a + * default-constructed instance of `ExcT`. */ template [[noreturn]] void logErrorErrnoAndThrow(const char * const fileName, @@ -414,14 +412,14 @@ public: const char * const initMsg, const char * const fmt, ArgTs&&...args) const { - this->logErrnoNoThrow(fileName, funcName, lineNo, initMsg, fmt, - std::forward(args)...); + this->logErrno(fileName, funcName, lineNo, initMsg, fmt, + std::forward(args)...); throw ExcT {}; } /* - * Like logErrnoStrNoThrow() with the `Level::Error` level, but also - * throws a default-constructed instance of `ExcT`. + * Like logErrnoStr() with the `Level::Error` level, but also throws + * a default-constructed instance of `ExcT`. */ template [[noreturn]] void @@ -429,14 +427,12 @@ public: const unsigned int lineNo, const char * const initMsg, const char * const msg) const { - this->logErrnoStrNoThrow(fileName, funcName, lineNo, initMsg, - msg); + this->logErrnoStr(fileName, funcName, lineNo, initMsg, msg); throw ExcT {}; } /* - * Like logErrnoNoThrow() with the `Level::Error` level, but also - * rethrows. + * Like logErrno() with the `Level::Error` level, but also rethrows. */ template [[noreturn]] void logErrorErrnoAndRethrow(const char * const fileName, @@ -444,13 +440,13 @@ public: const unsigned int lineNo, const char * const initMsg, const char * const fmt, ArgTs&&...args) const { - this->logErrnoNoThrow(fileName, funcName, lineNo, initMsg, fmt, - std::forward(args)...); + this->logErrno(fileName, funcName, lineNo, initMsg, fmt, + std::forward(args)...); throw; } /* - * Like logErrnoStrNoThrow() with the `Level::Error` level, but also + * Like logErrnoStr() with the `Level::Error` level, but also * rethrows. */ template @@ -459,8 +455,7 @@ public: const unsigned int lineNo, const char * const initMsg, const char * const msg) const { - this->logErrnoStrNoThrow(fileName, funcName, lineNo, initMsg, - msg); + this->logErrnoStr(fileName, funcName, lineNo, initMsg, msg); throw; } @@ -485,12 +480,12 @@ public: * the log message. */ template - void logMemNoThrow(const char * const fileName, const char * const funcName, - const unsigned int lineNo, const void * const memData, - const unsigned int memLen, const char * const fmt, ArgTs&&...args) const + void logMem(const char * const fileName, const char * const funcName, const unsigned int lineNo, + const void * const memData, const unsigned int memLen, const char * const fmt, + ArgTs&&...args) const { - this->_logNoThrow<_MemLogWriter, LevelV, false>(fileName, funcName, lineNo, memData, memLen, - "", fmt, std::forward(args)...); + this->_log<_MemLogWriter, LevelV, false>(fileName, funcName, lineNo, memData, memLen, "", + fmt, std::forward(args)...); } /* @@ -498,24 +493,23 @@ public: * message `msg`. */ template - void logMemStrNoThrow(const char * const fileName, const char * const funcName, - const unsigned int lineNo, const void * const memData, - const unsigned int memLen, const char * const msg) const + void logMemStr(const char * const fileName, const char * const funcName, + const unsigned int lineNo, const void * const memData, const unsigned int memLen, + const char * const msg) const { - this->_logStrNoThrow<_MemLogWriter, LevelV, false>(fileName, funcName, lineNo, memData, - memLen, "", msg); + this->_logStr<_MemLogWriter, LevelV, false>(fileName, funcName, lineNo, memData, memLen, "", + msg); } private: /* * Formats a log message with fmt::format() given `fmt` and `args`, - * and then forwards everything to _logStrNoThrow(). + * and then forwards everything to _logStr(). */ template - void _logNoThrow(const char * const fileName, const char * const funcName, - const unsigned int lineNo, const void * const memData, - const std::size_t memLen, const char * const initMsg, const char * const fmt, - ArgTs&&...args) const + void _log(const char * const fileName, const char * const funcName, const unsigned int lineNo, + const void * const memData, const std::size_t memLen, const char * const initMsg, + const char * const fmt, ArgTs&&...args) const { /* Only format arguments if logging or appending an error cause */ if (G_UNLIKELY(this->wouldLog(LevelV) || AppendCauseV)) { @@ -528,8 +522,8 @@ private: _mBuf.push_back('\0'); } - this->_logStrNoThrow(fileName, funcName, lineNo, memData, - memLen, initMsg, _mBuf.data()); + this->_logStr(fileName, funcName, lineNo, memData, memLen, + initMsg, _mBuf.data()); } /* @@ -541,10 +535,9 @@ private: * `initMsg` and `msg` as the message. */ template - void _logStrNoThrow(const char * const fileName, const char * const funcName, - const unsigned int lineNo, const void * const memData, - const std::size_t memLen, const char * const initMsg, - const char * const msg) const + void _logStr(const char * const fileName, const char * const funcName, + const unsigned int lineNo, const void * const memData, const std::size_t memLen, + const char * const initMsg, const char * const msg) const { /* Initial message and main message are required */ BT_ASSERT(initMsg); @@ -603,14 +596,12 @@ private: #define _BT_CPPLOG_DEF_LOGGER _mLogger /* - * Calls logNoThrow() on `_logger` to log using the level `_lvl` without - * appending nor throwing. + * Calls log() on `_logger` to log using the level `_lvl`. */ #define BT_CPPLOG_EX(_lvl, _logger, _fmt, ...) \ do { \ if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \ - (_logger).logNoThrow<(_lvl), false>(__FILE__, __func__, __LINE__, (_fmt), \ - ##__VA_ARGS__); \ + (_logger).log<(_lvl), false>(__FILE__, __func__, __LINE__, (_fmt), ##__VA_ARGS__); \ } \ } while (0) @@ -642,11 +633,10 @@ private: #define BT_CPPLOGF(_fmt, ...) BT_CPPLOGF_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__) /* - * Calls logStrNoThrow() on `_logger` to log using the level `_lvl` - * without appending nor throwing. + * Calls logStr() on `_logger` to log using the level `_lvl`. */ #define BT_CPPLOG_STR_EX(_lvl, _logger, _msg) \ - (_logger).logStrNoThrow<(_lvl), false>(__FILE__, __func__, __LINE__, (_msg)) + (_logger).logStr<(_lvl), false>(__FILE__, __func__, __LINE__, (_msg)) /* * BT_CPPLOG_STR_EX() with specific logging levels. @@ -676,14 +666,13 @@ private: #define BT_CPPLOGF_STR(_msg) BT_CPPLOGF_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_msg)) /* - * Calls logMemNoThrow() on `_logger` to log using the level `_lvl` - * without appending nor throwing. + * Calls logMem() on `_logger` to log using the level `_lvl`. */ #define BT_CPPLOG_MEM_EX(_lvl, _logger, _mem_data, _mem_len, _fmt, ...) \ do { \ if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \ - (_logger).logMemNoThrow<(_lvl)>(__FILE__, __func__, __LINE__, (_mem_data), (_mem_len), \ - (_fmt), ##__VA_ARGS__); \ + (_logger).logMem<(_lvl)>(__FILE__, __func__, __LINE__, (_mem_data), (_mem_len), \ + (_fmt), ##__VA_ARGS__); \ } \ } while (0) @@ -727,12 +716,10 @@ private: BT_CPPLOGF_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_fmt), ##__VA_ARGS__) /* - * Calls logMemStrNoThrow() on `_logger` to log using the level `_lvl` - * without appending nor throwing. + * Calls logMemStr() on `_logger` to log using the level `_lvl`. */ #define BT_CPPLOG_MEM_STR_EX(_lvl, _logger, _mem_data, _mem_len, _msg) \ - (_logger).logMemStrNoThrow<(_lvl)>(__FILE__, __func__, __LINE__, (_mem_data), (_mem_len), \ - (_msg)) + (_logger).logMemStr<(_lvl)>(__FILE__, __func__, __LINE__, (_mem_data), (_mem_len), (_msg)) /* * BT_CPPLOG_MEM_STR_EX() with specific logging levels. @@ -768,14 +755,14 @@ private: BT_CPPLOGF_MEM_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_msg)) /* - * Calls logErrnoNoThrow() on `_logger` to log using the level `_lvl` - * and initial message `_init_msg` without appending nor throwing. + * Calls logErrno() on `_logger` to log using the level `_lvl` and + * initial message `_init_msg`. */ #define BT_CPPLOG_ERRNO_EX(_lvl, _logger, _init_msg, _fmt, ...) \ do { \ if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \ - (_logger).logErrnoNoThrow<(_lvl), false>(__FILE__, __func__, __LINE__, (_init_msg), \ - (_fmt), ##__VA_ARGS__); \ + (_logger).logErrno<(_lvl), false>(__FILE__, __func__, __LINE__, (_init_msg), (_fmt), \ + ##__VA_ARGS__); \ } \ } while (0) @@ -813,11 +800,11 @@ private: BT_CPPLOGF_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_fmt), ##__VA_ARGS__) /* - * Calls logErrnoStrNoThrow() on `_logger` to log using the level `_lvl` - * and initial message `_init_msg` without appending nor throwing. + * Calls logErrnoStr() on `_logger` to log using the level `_lvl` and + * initial message `_init_msg`. */ #define BT_CPPLOG_ERRNO_STR_EX(_lvl, _logger, _init_msg, _msg) \ - (_logger).logErrnoStrNoThrow<(_lvl), false>(__FILE__, __func__, __LINE__, (_init_msg), (_msg)) + (_logger).logErrnoStr<(_lvl), false>(__FILE__, __func__, __LINE__, (_init_msg), (_msg)) /* * BT_CPPLOG_ERRNO_STR_EX() with specific logging levels.