2 * SPDX-FileCopyrightText: 2023 Philippe Proulx <pproulx@efficios.com>
3 * SPDX-License-Identifier: MIT
6 #ifndef BABELTRACE_CPP_COMMON_BT2C_LOGGING_HPP
7 #define BABELTRACE_CPP_COMMON_BT2C_LOGGING_HPP
17 #include <babeltrace2/babeltrace.h>
19 #include "common/assert.h"
20 #include "cpp-common/bt2/private-query-executor.hpp"
21 #include "cpp-common/bt2/self-component-class.hpp"
22 #include "cpp-common/bt2/self-component-port.hpp"
23 #include "cpp-common/bt2/self-message-iterator.hpp"
24 #include "cpp-common/bt2s/optional.hpp"
25 #include "cpp-common/bt2s/span.hpp"
26 #include "cpp-common/vendor/fmt/core.h"
27 #include "cpp-common/vendor/wise-enum/wise_enum.h"
28 #include "logging/log-api.h"
33 * A logger contains an actor (self component class, self component,
34 * self message iterator, or simple module name), a current logging
35 * level, and a logging tag.
37 * It offers the log(), logMem(), logErrno(), logErrorAndThrow(),
38 * logErrorAndRethrow(), logErrorErrnoAndThrow(), and
39 * logErrorErrnoAndRethrow() method templates to log using a given
40 * level, optionally append a cause to the error of the current thread
41 * using the correct actor, and optionally throw or rethrow.
43 * The methods above expect a format string and zero or more arguments
44 * to be formatted with fmt::format().
49 using MemData = bt2s::span<const std::uint8_t>;
51 /* clang-format off */
53 /* Available log levels */
54 WISE_ENUM_CLASS_MEMBER(Level,
55 (Trace, BT_LOG_TRACE),
56 (Debug, BT_LOG_DEBUG),
58 (Warning, BT_LOG_WARNING),
59 (Error, BT_LOG_ERROR),
60 (Fatal, BT_LOG_FATAL),
67 * Builds a logger from the self component class `selfCompCls` using
68 * the tag `tag` and the logging level of `privQueryExec`.
70 explicit Logger(const bt2::SelfComponentClass selfCompCls,
71 const bt2::PrivateQueryExecutor privQueryExec, std::string tag) noexcept :
72 _mSelfCompCls {selfCompCls},
73 _mLevel {static_cast<Level>(privQueryExec.loggingLevel())}, _mTag {std::move(tag)}
78 * Builds a logger from the self component `selfComp` using the tag
81 explicit Logger(const bt2::SelfComponent selfComp, std::string tag) noexcept :
82 _mSelfComp {selfComp}, _mLevel {static_cast<Level>(selfComp.loggingLevel())}, _mTag {
89 * Builds a logger from the self source component `selfComp` using
92 explicit Logger(const bt2::SelfSourceComponent selfComp, std::string tag) noexcept :
94 bt2::SelfComponent {bt_self_component_source_as_self_component(selfComp.libObjPtr())},
100 * Builds a logger from the self filter component `selfComp` using
103 explicit Logger(const bt2::SelfFilterComponent selfComp, std::string tag) noexcept :
105 bt2::SelfComponent {bt_self_component_filter_as_self_component(selfComp.libObjPtr())},
111 * Builds a logger from the self sink component `selfComp` using the
114 explicit Logger(const bt2::SelfSinkComponent selfComp, std::string tag) noexcept :
115 Logger {bt2::SelfComponent {bt_self_component_sink_as_self_component(selfComp.libObjPtr())},
121 * Builds a logger from the self message iterator `selfMsgIter`
122 * using the tag `tag`.
124 explicit Logger(const bt2::SelfMessageIterator selfMsgIter, std::string tag) noexcept :
125 _mSelfMsgIter {selfMsgIter},
126 _mLevel {static_cast<Level>(selfMsgIter.component().loggingLevel())}, _mTag {std::move(tag)}
131 * Builds a logger from the module named `moduleName` using the tag
132 * `tag` and logging level `logLevel`.
134 explicit Logger(std::string moduleName, std::string tag, const Level logLevel) noexcept :
135 _mModuleName {std::move(moduleName)}, _mLevel {logLevel}, _mTag {std::move(tag)}
140 * Builds a logger from another logger `other` using the new tag
143 explicit Logger(const Logger& other, std::string newTag) :
144 _mSelfCompCls {other._mSelfCompCls}, _mSelfComp {other._mSelfComp},
145 _mSelfMsgIter {other._mSelfMsgIter},
146 _mModuleName {other._mModuleName}, _mLevel {other._mLevel}, _mTag {std::move(newTag)}
151 * Current logging level.
153 Level level() const noexcept
159 * Whether or not this logger would log at the level `level`.
161 bool wouldLog(const Level level) const noexcept
163 return BT_LOG_ON_CUR_LVL(static_cast<int>(level), static_cast<int>(_mLevel));
167 * Whether or not this logger would log at the trace level.
169 bool wouldLogT() const noexcept
171 return this->wouldLog(Level::Trace);
175 * Whether or not this logger would log at the debug level.
177 bool wouldLogD() const noexcept
179 return this->wouldLog(Level::Debug);
183 * Whether or not this logger would log at the info level.
185 bool wouldLogI() const noexcept
187 return this->wouldLog(Level::Info);
191 * Whether or not this logger would log at the warning level.
193 bool wouldLogW() const noexcept
195 return this->wouldLog(Level::Warning);
199 * Whether or not this logger would log at the error level.
201 bool wouldLogE() const noexcept
203 return this->wouldLog(Level::Error);
207 * Whether or not this logger would log at the fatal level.
209 bool wouldLogF() const noexcept
211 return this->wouldLog(Level::Fatal);
217 const std::string& tag() const noexcept
223 * Self component class actor, or `bt2s::nullopt` if none.
225 const bt2s::optional<bt2::SelfComponentClass>& selfCompCls() const noexcept
227 return _mSelfCompCls;
231 * Self component actor, or `bt2s::nullopt` if none.
233 const bt2s::optional<bt2::SelfComponent>& selfComp() const noexcept
239 * Self message iterator actor, or `bt2s::nullopt` if none.
241 const bt2s::optional<bt2::SelfMessageIterator>& selfMsgIter() const noexcept
243 return _mSelfMsgIter;
247 * Name of module actor, or `bt2s::nullopt` if none.
249 const bt2s::optional<std::string>& moduleName() const noexcept
255 struct _StdLogWriter final
257 static void write(const char * const fileName, const char * const funcName,
258 const unsigned lineNo, const Level level, const char * const tag, MemData,
259 const char * const initMsg, const char * const msg) noexcept
261 BT_ASSERT_DBG(initMsg && std::strcmp(initMsg, "") == 0);
262 bt_log_write(fileName, funcName, lineNo, static_cast<bt_log_level>(level), tag, msg);
268 * Logs using the level `LevelV`.
270 * This method forwards `fmt` and `args` to fmt::format() to create
273 * If `AppendCauseV` is true, this method also appends a cause to
274 * the error of the current thread using the same message.
276 template <Level LevelV, bool AppendCauseV, typename... ArgTs>
277 void log(const char * const fileName, const char * const funcName, const unsigned int lineNo,
278 fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
280 this->_log<_StdLogWriter, LevelV, AppendCauseV>(
281 fileName, funcName, lineNo, {}, "", std::move(fmt), std::forward<ArgTs>(args)...);
285 * Like log() with the `Level::Error` level, but also throws a
286 * default-constructed instance of `ExcT`.
288 template <bool AppendCauseV, typename ExcT, typename... ArgTs>
289 [[noreturn]] void logErrorAndThrow(const char * const fileName, const char * const funcName,
290 const unsigned int lineNo, fmt::format_string<ArgTs...> fmt,
291 ArgTs&&...args) const
293 this->log<Level::Error, AppendCauseV>(fileName, funcName, lineNo, std::move(fmt),
294 std::forward<ArgTs>(args)...);
299 * Like log() with the `Level::Error` level, but also rethrows.
301 template <bool AppendCauseV, typename... ArgTs>
302 [[noreturn]] void logErrorAndRethrow(const char * const fileName, const char * const funcName,
303 const unsigned int lineNo,
304 fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
306 this->log<Level::Error, AppendCauseV>(fileName, funcName, lineNo, std::move(fmt),
307 std::forward<ArgTs>(args)...);
312 struct _InitMsgLogWriter final
314 static void write(const char * const fileName, const char * const funcName,
315 const unsigned lineNo, const Level level, const char * const tag, MemData,
316 const char * const initMsg, const char * const msg) noexcept
318 bt_log_write_printf(funcName, fileName, lineNo, static_cast<bt_log_level>(level), tag,
319 "%s%s", initMsg, msg);
325 * Logs the message of `errno` using the level `LevelV`.
327 * The log message starts with `initMsg`, is followed with the
328 * message for `errno`, and then with what fmt::format() creates
329 * given `fmt` and `args`.
331 * If `AppendCauseV` is true, this method also appends a cause to
332 * the error of the current thread using the same message.
334 template <Level LevelV, bool AppendCauseV, typename... ArgTs>
335 void logErrno(const char * const fileName, const char * const funcName,
336 const unsigned int lineNo, const char * const initMsg,
337 fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
339 this->_log<_InitMsgLogWriter, LevelV, AppendCauseV>(
340 fileName, funcName, lineNo, {}, this->_errnoIntroStr(initMsg).c_str(), std::move(fmt),
341 std::forward<ArgTs>(args)...);
345 * Like logErrno() with the `Level::Error` level, but also throws a
346 * default-constructed instance of `ExcT`.
348 template <bool AppendCauseV, typename ExcT, typename... ArgTs>
349 [[noreturn]] void logErrorErrnoAndThrow(const char * const fileName,
350 const char * const funcName, const unsigned int lineNo,
351 const char * const initMsg,
352 fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
354 this->logErrno<Level::Error, AppendCauseV>(fileName, funcName, lineNo, initMsg,
355 std::move(fmt), std::forward<ArgTs>(args)...);
360 * Like logErrno() with the `Level::Error` level, but also rethrows.
362 template <bool AppendCauseV, typename... ArgTs>
364 logErrorErrnoAndRethrow(const char * const fileName, const char * const funcName,
365 const unsigned int lineNo, const char * const initMsg,
366 fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
368 this->logErrno<Level::Error, AppendCauseV>(fileName, funcName, lineNo, initMsg,
369 std::move(fmt), std::forward<ArgTs>(args)...);
374 struct _MemLogWriter final
376 static void write(const char * const fileName, const char * const funcName,
377 const unsigned lineNo, const Level level, const char * const tag,
378 const MemData memData, const char *, const char * const msg) noexcept
380 bt_log_write_mem(funcName, fileName, lineNo, static_cast<bt_log_level>(level), tag,
381 memData.data(), memData.size(), msg);
387 * Logs memory data using the level `LevelV`.
389 * This method forwards `fmt` and `args` to fmt::format() to create
392 template <Level LevelV, typename... ArgTs>
393 void logMem(const char * const fileName, const char * const funcName, const unsigned int lineNo,
394 const MemData memData, fmt::format_string<ArgTs...> fmt, ArgTs&&...args) const
396 this->_log<_MemLogWriter, LevelV, false>(fileName, funcName, lineNo, memData, "",
397 std::move(fmt), std::forward<ArgTs>(args)...);
402 * Formats a log message with fmt::format() given `fmt` and `args`,
405 * 1. Calls LogWriterT::write() with its arguments to log using the
408 * 2. If `AppendCauseV` is true, this method also appends a cause to
409 * the error of the current thread using the concatenation of
410 * `initMsg` and `msg` as the message.
412 template <typename LogWriterT, Level LevelV, bool AppendCauseV, typename... ArgTs>
413 void _log(const char * const fileName, const char * const funcName, const unsigned int lineNo,
414 const MemData memData, const char * const initMsg, fmt::format_string<ArgTs...> fmt,
415 ArgTs&&...args) const
417 const auto wouldLog = this->wouldLog(LevelV);
419 /* Only format arguments if logging or appending an error cause */
420 if (G_UNLIKELY(wouldLog || AppendCauseV)) {
422 * Format arguments to our buffer (fmt::format_to() doesn't
423 * append a null character).
426 fmt::format_to(std::back_inserter(_mBuf), std::move(fmt), std::forward<ArgTs>(args)...);
427 _mBuf.push_back('\0');
430 /* Initial message is required */
435 LogWriterT::write(fileName, funcName, lineNo, LevelV, _mTag.data(), memData, initMsg,
439 /* Append an error cause if needed */
442 bt_current_thread_error_append_cause_from_message_iterator(
443 _mSelfMsgIter->libObjPtr(), fileName, lineNo, "%s%s", initMsg, _mBuf.data());
444 } else if (_mSelfComp) {
445 bt_current_thread_error_append_cause_from_component(
446 _mSelfComp->libObjPtr(), fileName, lineNo, "%s%s", initMsg, _mBuf.data());
447 } else if (_mSelfCompCls) {
448 bt_current_thread_error_append_cause_from_component_class(
449 _mSelfCompCls->libObjPtr(), fileName, lineNo, "%s%s", initMsg, _mBuf.data());
451 BT_ASSERT(_mModuleName);
452 bt_current_thread_error_append_cause_from_unknown(
453 _mModuleName->data(), fileName, lineNo, "%s%s", initMsg, _mBuf.data());
458 static std::string _errnoIntroStr(const char * const initMsg)
460 BT_ASSERT(errno != 0);
461 return fmt::format("{}: {}", initMsg, g_strerror(errno));
464 /* Exactly one of the following four members has a value */
465 bt2s::optional<bt2::SelfComponentClass> _mSelfCompCls;
466 bt2s::optional<bt2::SelfComponent> _mSelfComp;
467 bt2s::optional<bt2::SelfMessageIterator> _mSelfMsgIter;
468 bt2s::optional<std::string> _mModuleName;
470 /* Current logging level */
476 /* Formatting buffer */
477 mutable std::vector<char> _mBuf;
481 * Returns `s` if it's not `nullptr`, or the `(null)` string otherwise.
483 inline const char *maybeNull(const char * const s) noexcept
485 return s ? s : "(null)";
488 } /* namespace bt2c */
490 /* Internal: default logger name */
491 #define _BT_CPPLOG_DEF_LOGGER _mLogger
494 * Calls log() on `_logger` to log using the level `_lvl`.
496 #define BT_CPPLOG_EX(_lvl, _logger, _fmt, ...) \
498 if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \
499 (_logger).template log<(_lvl), false>(__FILE__, __func__, __LINE__, (_fmt), \
505 * BT_CPPLOG_EX() with specific logging levels.
507 #define BT_CPPLOGT_SPEC(_logger, _fmt, ...) \
508 BT_CPPLOG_EX(bt2c::Logger::Level::Trace, (_logger), (_fmt), ##__VA_ARGS__)
509 #define BT_CPPLOGD_SPEC(_logger, _fmt, ...) \
510 BT_CPPLOG_EX(bt2c::Logger::Level::Debug, (_logger), (_fmt), ##__VA_ARGS__)
511 #define BT_CPPLOGI_SPEC(_logger, _fmt, ...) \
512 BT_CPPLOG_EX(bt2c::Logger::Level::Info, (_logger), (_fmt), ##__VA_ARGS__)
513 #define BT_CPPLOGW_SPEC(_logger, _fmt, ...) \
514 BT_CPPLOG_EX(bt2c::Logger::Level::Warning, (_logger), (_fmt), ##__VA_ARGS__)
515 #define BT_CPPLOGE_SPEC(_logger, _fmt, ...) \
516 BT_CPPLOG_EX(bt2c::Logger::Level::Error, (_logger), (_fmt), ##__VA_ARGS__)
517 #define BT_CPPLOGF_SPEC(_logger, _fmt, ...) \
518 BT_CPPLOG_EX(bt2c::Logger::Level::Fatal, (_logger), (_fmt), ##__VA_ARGS__)
521 * BT_CPPLOG_EX() with specific logging levels and using the default
524 #define BT_CPPLOGT(_fmt, ...) BT_CPPLOGT_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
525 #define BT_CPPLOGD(_fmt, ...) BT_CPPLOGD_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
526 #define BT_CPPLOGI(_fmt, ...) BT_CPPLOGI_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
527 #define BT_CPPLOGW(_fmt, ...) BT_CPPLOGW_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
528 #define BT_CPPLOGE(_fmt, ...) BT_CPPLOGE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
529 #define BT_CPPLOGF(_fmt, ...) BT_CPPLOGF_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
532 * Calls logMem() on `_logger` to log using the level `_lvl`.
534 #define BT_CPPLOG_MEM_EX(_lvl, _logger, _memData, _fmt, ...) \
536 if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \
537 (_logger).template logMem<(_lvl)>(__FILE__, __func__, __LINE__, (_memData), (_fmt), \
543 * BT_CPPLOG_MEM_EX() with specific logging levels.
545 #define BT_CPPLOGT_MEM_SPEC(_logger, _memData, _fmt, ...) \
546 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Trace, (_logger), (_memData), (_fmt), ##__VA_ARGS__)
547 #define BT_CPPLOGD_MEM_SPEC(_logger, _memData, _fmt, ...) \
548 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Debug, (_logger), (_memData), (_fmt), ##__VA_ARGS__)
549 #define BT_CPPLOGI_MEM_SPEC(_logger, _memData, _fmt, ...) \
550 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Info, (_logger), (_memData), (_fmt), ##__VA_ARGS__)
551 #define BT_CPPLOGW_MEM_SPEC(_logger, _memData, _fmt, ...) \
552 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Warning, (_logger), (_memData), (_fmt), ##__VA_ARGS__)
553 #define BT_CPPLOGE_MEM_SPEC(_logger, _memData, _fmt, ...) \
554 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Error, (_logger), (_memData), (_fmt), ##__VA_ARGS__)
555 #define BT_CPPLOGF_MEM_SPEC(_logger, _memData, _fmt, ...) \
556 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Fatal, (_logger), (_memData), (_fmt), ##__VA_ARGS__)
559 * BT_CPPLOG_MEM_EX() with specific logging levels and using the default
562 #define BT_CPPLOGT_MEM(_memData, _fmt, ...) \
563 BT_CPPLOGT_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_memData), (_fmt), ##__VA_ARGS__)
564 #define BT_CPPLOGD_MEM(_memData, _fmt, ...) \
565 BT_CPPLOGD_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_memData), (_fmt), ##__VA_ARGS__)
566 #define BT_CPPLOGI_MEM(_memData, _fmt, ...) \
567 BT_CPPLOGI_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_memData), (_fmt), ##__VA_ARGS__)
568 #define BT_CPPLOGW_MEM(_memData, _fmt, ...) \
569 BT_CPPLOGW_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_memData), (_fmt), ##__VA_ARGS__)
570 #define BT_CPPLOGE_MEM(_memData, _fmt, ...) \
571 BT_CPPLOGE_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_memData), (_fmt), ##__VA_ARGS__)
572 #define BT_CPPLOGF_MEM(_memData, _fmt, ...) \
573 BT_CPPLOGF_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_memData), (_fmt), ##__VA_ARGS__)
576 * Calls logErrno() on `_logger` to log using the level `_lvl` and
577 * initial message `_initMsg`.
579 #define BT_CPPLOG_ERRNO_EX(_lvl, _logger, _initMsg, _fmt, ...) \
581 if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \
582 (_logger).template logErrno<(_lvl), false>(__FILE__, __func__, __LINE__, (_initMsg), \
583 (_fmt), ##__VA_ARGS__); \
588 * BT_CPPLOG_ERRNO_EX() with specific logging levels.
590 #define BT_CPPLOGT_ERRNO_SPEC(_logger, _initMsg, _fmt, ...) \
591 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Trace, (_logger), (_initMsg), (_fmt), ##__VA_ARGS__)
592 #define BT_CPPLOGD_ERRNO_SPEC(_logger, _initMsg, _fmt, ...) \
593 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Debug, (_logger), (_initMsg), (_fmt), ##__VA_ARGS__)
594 #define BT_CPPLOGI_ERRNO_SPEC(_logger, _initMsg, _fmt, ...) \
595 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Info, (_logger), (_initMsg), (_fmt), ##__VA_ARGS__)
596 #define BT_CPPLOGW_ERRNO_SPEC(_logger, _initMsg, _fmt, ...) \
597 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Warning, (_logger), (_initMsg), (_fmt), ##__VA_ARGS__)
598 #define BT_CPPLOGE_ERRNO_SPEC(_logger, _initMsg, _fmt, ...) \
599 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Error, (_logger), (_initMsg), (_fmt), ##__VA_ARGS__)
600 #define BT_CPPLOGF_ERRNO_SPEC(_logger, _initMsg, _fmt, ...) \
601 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Fatal, (_logger), (_initMsg), (_fmt), ##__VA_ARGS__)
604 * BT_CPPLOG_ERRNO_EX() with specific logging levels and using the
607 #define BT_CPPLOGT_ERRNO(_initMsg, _fmt, ...) \
608 BT_CPPLOGT_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_initMsg), (_fmt), ##__VA_ARGS__)
609 #define BT_CPPLOGD_ERRNO(_initMsg, _fmt, ...) \
610 BT_CPPLOGD_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_initMsg), (_fmt), ##__VA_ARGS__)
611 #define BT_CPPLOGI_ERRNO(_initMsg, _fmt, ...) \
612 BT_CPPLOGI_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_initMsg), (_fmt), ##__VA_ARGS__)
613 #define BT_CPPLOGW_ERRNO(_initMsg, _fmt, ...) \
614 BT_CPPLOGW_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_initMsg), (_fmt), ##__VA_ARGS__)
615 #define BT_CPPLOGE_ERRNO(_initMsg, _fmt, ...) \
616 BT_CPPLOGE_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_initMsg), (_fmt), ##__VA_ARGS__)
617 #define BT_CPPLOGF_ERRNO(_initMsg, _fmt, ...) \
618 BT_CPPLOGF_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_initMsg), (_fmt), ##__VA_ARGS__)
621 * Calls log() on `_logger` with the `Error` level to log an error and
622 * append a cause to the error of the current thread.
624 #define BT_CPPLOGE_APPEND_CAUSE_SPEC(_logger, _fmt, ...) \
625 (_logger).template log<bt2c::Logger::Level::Error, true>(__FILE__, __func__, __LINE__, (_fmt), \
629 * BT_CPPLOGE_APPEND_CAUSE_SPEC() using the default logger.
631 #define BT_CPPLOGE_APPEND_CAUSE(_fmt, ...) \
632 BT_CPPLOGE_APPEND_CAUSE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
635 * Calls logErrorAndThrow() on `_logger` to log an error, append a cause
636 * to the error of the current thread, and throw an instance of
639 #define BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(_logger, _excCls, _fmt, ...) \
640 (_logger).template logErrorAndThrow<true, _excCls>(__FILE__, __func__, __LINE__, (_fmt), \
644 * BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC() using the default logger.
646 #define BT_CPPLOGE_APPEND_CAUSE_AND_THROW(_excCls, _fmt, ...) \
647 BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(_BT_CPPLOG_DEF_LOGGER, _excCls, (_fmt), ##__VA_ARGS__)
650 * Calls logErrorAndRethrow() on `_logger` to log an error, append a
651 * cause to the error of the current thread, and throw an instance of
654 #define BT_CPPLOGE_APPEND_CAUSE_AND_RETHROW_SPEC(_logger, _fmt, ...) \
655 (_logger).template logErrorAndRethrow<true>(__FILE__, __func__, __LINE__, (_fmt), ##__VA_ARGS__)
658 * BT_CPPLOGE_APPEND_CAUSE_AND_RETHROW_SPEC() using the default logger.
660 #define BT_CPPLOGE_APPEND_CAUSE_AND_RETHROW(_fmt, ...) \
661 BT_CPPLOGE_APPEND_CAUSE_AND_RETHROW_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
664 * Calls logErrno() on `_logger` with the `Level::Error` level to log an
665 * error and append a cause to the error of the current thread.
667 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(_logger, _initMsg, _fmt, ...) \
668 (_logger).template logErrno<bt2c::Logger::Level::Error, true>( \
669 __FILE__, __func__, __LINE__, (_initMsg), (_fmt), ##__VA_ARGS__)
672 * BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC() using the default logger.
674 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE(_initMsg, _fmt, ...) \
675 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_initMsg), (_fmt), ##__VA_ARGS__)
678 * Calls logErrorErrnoAndThrow() on `_logger` to log an error, append a
679 * cause to the error of the current thread, and throw an instance of
682 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_THROW_SPEC(_logger, _excCls, _initMsg, _fmt, ...) \
683 (_logger).template logErrorErrnoAndThrow<true, _excCls>(__FILE__, __func__, __LINE__, \
684 (_initMsg), (_fmt), ##__VA_ARGS__)
687 * BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_THROW_SPEC() using the default
690 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_THROW(_excCls, _initMsg, _fmt, ...) \
691 BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_THROW_SPEC(_BT_CPPLOG_DEF_LOGGER, _excCls, (_initMsg), \
692 (_fmt), ##__VA_ARGS__)
695 * Calls logErrorErrnoAndRethrow() on `_logger` to log an error, append
696 * a cause to the error of the current thread, and throw an instance of
699 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_SPEC(_logger, _initMsg, _fmt, ...) \
700 (_logger).template logErrorErrnoAndRethrow<true>(__FILE__, __func__, __LINE__, (_initMsg), \
701 (_fmt), ##__VA_ARGS__)
704 * BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_SPEC() using the default
707 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW(_initMsg, _fmt, ...) \
708 BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_SPEC(_BT_CPPLOG_DEF_LOGGER, (_initMsg), (_fmt), \
711 #endif /* BABELTRACE_CPP_COMMON_BT2C_LOGGING_HPP */