cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / cpp-common / bt2c / logging.hpp
1 /*
2 * SPDX-FileCopyrightText: 2023 Philippe Proulx <pproulx@efficios.com>
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef BABELTRACE_CPP_COMMON_BT2C_LOGGING_HPP
7 #define BABELTRACE_CPP_COMMON_BT2C_LOGGING_HPP
8
9 #include <cstring>
10 #include <iterator>
11 #include <string>
12 #include <utility>
13 #include <vector>
14
15 #include <glib.h>
16
17 #include <babeltrace2/babeltrace.h>
18
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/vendor/fmt/core.h"
26 #include "cpp-common/vendor/wise-enum/wise_enum.h"
27 #include "logging/log-api.h"
28
29 namespace bt2c {
30
31 /*
32 * A logger contains an actor (self component class, self component,
33 * self message iterator, or simple module name), a current logging
34 * level, and a logging tag.
35 *
36 * It offers the log(), logMem(), logErrno(), logErrorAndThrow(),
37 * logErrorAndRethrow(), logErrorErrnoAndThrow(), and
38 * logErrorErrnoAndRethrow() method templates to log using a given
39 * level, optionally append a cause to the error of the current thread
40 * using the correct actor, and optionally throw or rethrow.
41 *
42 * The methods above expect a format string and zero or more arguments
43 * to be formatted with fmt::format().
44 */
45 class Logger final
46 {
47 public:
48 /* clang-format off */
49
50 /* Available log levels */
51 WISE_ENUM_CLASS_MEMBER(Level,
52 (Trace, BT_LOG_TRACE),
53 (Debug, BT_LOG_DEBUG),
54 (Info, BT_LOG_INFO),
55 (Warning, BT_LOG_WARNING),
56 (Error, BT_LOG_ERROR),
57 (Fatal, BT_LOG_FATAL),
58 (None, BT_LOG_NONE));
59
60 /* clang-format on */
61
62 /*
63 * Builds a logger from the self component class `selfCompCls` using
64 * the tag `tag` and the logging level of `privQueryExec`.
65 */
66 explicit Logger(const bt2::SelfComponentClass selfCompCls,
67 const bt2::PrivateQueryExecutor privQueryExec, std::string tag) noexcept :
68 _mSelfCompCls {selfCompCls},
69 _mLevel {static_cast<Level>(privQueryExec.loggingLevel())}, _mTag {std::move(tag)}
70 {
71 }
72
73 /*
74 * Builds a logger from the self component `selfComp` using the tag
75 * `tag`.
76 */
77 explicit Logger(const bt2::SelfComponent selfComp, std::string tag) noexcept :
78 _mSelfComp {selfComp}, _mLevel {static_cast<Level>(selfComp.loggingLevel())}, _mTag {
79 std::move(
80 tag)}
81 {
82 }
83
84 /*
85 * Builds a logger from the self source component `selfComp` using
86 * the tag `tag`.
87 */
88 explicit Logger(const bt2::SelfSourceComponent selfComp, std::string tag) noexcept :
89 Logger {
90 bt2::SelfComponent {bt_self_component_source_as_self_component(selfComp.libObjPtr())},
91 std::move(tag)}
92 {
93 }
94
95 /*
96 * Builds a logger from the self filter component `selfComp` using
97 * the tag `tag`.
98 */
99 explicit Logger(const bt2::SelfFilterComponent selfComp, std::string tag) noexcept :
100 Logger {
101 bt2::SelfComponent {bt_self_component_filter_as_self_component(selfComp.libObjPtr())},
102 std::move(tag)}
103 {
104 }
105
106 /*
107 * Builds a logger from the self sink component `selfComp` using the
108 * tag `tag`.
109 */
110 explicit Logger(const bt2::SelfSinkComponent selfComp, std::string tag) noexcept :
111 Logger {bt2::SelfComponent {bt_self_component_sink_as_self_component(selfComp.libObjPtr())},
112 std::move(tag)}
113 {
114 }
115
116 /*
117 * Builds a logger from the self message iterator `selfMsgIter`
118 * using the tag `tag`.
119 */
120 explicit Logger(const bt2::SelfMessageIterator selfMsgIter, std::string tag) noexcept :
121 _mSelfMsgIter {selfMsgIter},
122 _mLevel {static_cast<Level>(selfMsgIter.component().loggingLevel())}, _mTag {std::move(tag)}
123 {
124 }
125
126 /*
127 * Builds a logger from the module named `moduleName` using the tag
128 * `tag` and logging level `logLevel`.
129 */
130 explicit Logger(std::string moduleName, std::string tag, const Level logLevel) noexcept :
131 _mModuleName {std::move(moduleName)}, _mLevel {logLevel}, _mTag {std::move(tag)}
132 {
133 }
134
135 /*
136 * Builds a logger from another logger `other` using the new tag
137 * `newTag`.
138 */
139 explicit Logger(const Logger& other, std::string newTag) :
140 _mSelfCompCls {other._mSelfCompCls}, _mSelfComp {other._mSelfComp},
141 _mSelfMsgIter {other._mSelfMsgIter},
142 _mModuleName {other._mModuleName}, _mLevel {other._mLevel}, _mTag {std::move(newTag)}
143 {
144 }
145
146 /*
147 * Current logging level.
148 */
149 Level level() const noexcept
150 {
151 return _mLevel;
152 }
153
154 /*
155 * Current logging level converted to a `bt_log_level` value.
156 *
157 * For legacy code.
158 */
159 bt_log_level cLevel() const noexcept
160 {
161 return static_cast<bt_log_level>(_mLevel);
162 }
163
164 /*
165 * Whether or not this logger would log at the level `level`.
166 */
167 bool wouldLog(const Level level) const noexcept
168 {
169 return BT_LOG_ON_CUR_LVL(static_cast<int>(level), static_cast<int>(_mLevel));
170 }
171
172 /*
173 * Whether or not this logger would log at the trace level.
174 */
175 bool wouldLogT() const noexcept
176 {
177 return this->wouldLog(Level::Trace);
178 }
179
180 /*
181 * Whether or not this logger would log at the debug level.
182 */
183 bool wouldLogD() const noexcept
184 {
185 return this->wouldLog(Level::Debug);
186 }
187
188 /*
189 * Whether or not this logger would log at the info level.
190 */
191 bool wouldLogI() const noexcept
192 {
193 return this->wouldLog(Level::Info);
194 }
195
196 /*
197 * Whether or not this logger would log at the warning level.
198 */
199 bool wouldLogW() const noexcept
200 {
201 return this->wouldLog(Level::Warning);
202 }
203
204 /*
205 * Whether or not this logger would log at the error level.
206 */
207 bool wouldLogE() const noexcept
208 {
209 return this->wouldLog(Level::Error);
210 }
211
212 /*
213 * Whether or not this logger would log at the fatal level.
214 */
215 bool wouldLogF() const noexcept
216 {
217 return this->wouldLog(Level::Fatal);
218 }
219
220 /*
221 * Logging tag.
222 */
223 const std::string& tag() const noexcept
224 {
225 return _mTag;
226 }
227
228 /*
229 * Self component class actor, or `bt2s::nullopt` if none.
230 */
231 const bt2s::optional<bt2::SelfComponentClass>& selfCompCls() const noexcept
232 {
233 return _mSelfCompCls;
234 }
235
236 /*
237 * Self component actor, or `bt2s::nullopt` if none.
238 */
239 const bt2s::optional<bt2::SelfComponent>& selfComp() const noexcept
240 {
241 return _mSelfComp;
242 }
243
244 /*
245 * Self message iterator actor, or `bt2s::nullopt` if none.
246 */
247 const bt2s::optional<bt2::SelfMessageIterator>& selfMsgIter() const noexcept
248 {
249 return _mSelfMsgIter;
250 }
251
252 /*
253 * Name of module actor, or `bt2s::nullopt` if none.
254 */
255 const bt2s::optional<std::string>& moduleName() const noexcept
256 {
257 return _mModuleName;
258 }
259
260 private:
261 struct _StdLogWriter final
262 {
263 static void write(const char * const fileName, const char * const funcName,
264 const unsigned lineNo, const Level level, const char * const tag,
265 const void *, unsigned int, const char * const initMsg,
266 const char * const msg) noexcept
267 {
268 BT_ASSERT_DBG(initMsg && std::strcmp(initMsg, "") == 0);
269 bt_log_write(fileName, funcName, lineNo, static_cast<bt_log_level>(level), tag, msg);
270 }
271 };
272
273 public:
274 /*
275 * Logs using the level `LevelV`.
276 *
277 * This method forwards `fmt` and `args` to fmt::format() to create
278 * the log message.
279 *
280 * If `AppendCauseV` is true, this method also appends a cause to
281 * the error of the current thread using the same message.
282 */
283 template <Level LevelV, bool AppendCauseV, typename... ArgTs>
284 void log(const char * const fileName, const char * const funcName, const unsigned int lineNo,
285 const char * const fmt, ArgTs&&...args) const
286 {
287 this->_log<_StdLogWriter, LevelV, AppendCauseV>(fileName, funcName, lineNo, nullptr, 0, "",
288 fmt, std::forward<ArgTs>(args)...);
289 }
290
291 /*
292 * Logs `msg` using the level `LevelV`.
293 *
294 * If `AppendCauseV` is true, this method also appends a cause to
295 * the error of the current thread using the same message.
296 */
297 template <Level LevelV, bool AppendCauseV>
298 void logStr(const char * const fileName, const char * const funcName, const unsigned int lineNo,
299 const char * const msg) const
300 {
301 this->_logStr<_StdLogWriter, LevelV, AppendCauseV>(fileName, funcName, lineNo, nullptr, 0,
302 "", msg);
303 }
304
305 /*
306 * Like log() with the `Level::Error` level, but also throws a
307 * default-constructed instance of `ExcT`.
308 */
309 template <bool AppendCauseV, typename ExcT, typename... ArgTs>
310 [[noreturn]] void logErrorAndThrow(const char * const fileName, const char * const funcName,
311 const unsigned int lineNo, const char * const fmt,
312 ArgTs&&...args) const
313 {
314 this->log<Level::Error, AppendCauseV>(fileName, funcName, lineNo, fmt,
315 std::forward<ArgTs>(args)...);
316 throw ExcT {};
317 }
318
319 /*
320 * Like logStr() with the `Level::Error` level, but also throws a
321 * default-constructed instance of `ExcT`.
322 */
323 template <bool AppendCauseV, typename ExcT>
324 [[noreturn]] void logErrorStrAndThrow(const char * const fileName, const char * const funcName,
325 const unsigned int lineNo, const char * const msg) const
326 {
327 this->logStr<Level::Error, AppendCauseV>(fileName, funcName, lineNo, msg);
328 throw ExcT {};
329 }
330
331 /*
332 * Like log() with the `Level::Error` level, but also rethrows.
333 */
334 template <bool AppendCauseV, typename... ArgTs>
335 [[noreturn]] void logErrorAndRethrow(const char * const fileName, const char * const funcName,
336 const unsigned int lineNo, const char * const fmt,
337 ArgTs&&...args) const
338 {
339 this->log<Level::Error, AppendCauseV>(fileName, funcName, lineNo, fmt,
340 std::forward<ArgTs>(args)...);
341 throw;
342 }
343
344 /*
345 * Like logStr() with the `Level::Error` level, but also rethrows.
346 */
347 template <bool AppendCauseV>
348 [[noreturn]] void logErrorStrAndRethrow(const char * const fileName,
349 const char * const funcName, const unsigned int lineNo,
350 const char * const msg) const
351 {
352 this->logStr<Level::Error, AppendCauseV>(fileName, funcName, lineNo, msg);
353 throw;
354 }
355
356 private:
357 struct _InitMsgLogWriter final
358 {
359 static void write(const char * const fileName, const char * const funcName,
360 const unsigned lineNo, const Level level, const char * const tag,
361 const void *, unsigned int, const char * const initMsg,
362 const char * const msg) noexcept
363 {
364 bt_log_write_printf(funcName, fileName, lineNo, static_cast<bt_log_level>(level), tag,
365 "%s%s", initMsg, msg);
366 }
367 };
368
369 public:
370 /*
371 * Logs the message of `errno` using the level `LevelV`.
372 *
373 * The log message starts with `initMsg`, is followed with the
374 * message for `errno`, and then with what fmt::format() creates
375 * given `fmt` and `args`.
376 *
377 * If `AppendCauseV` is true, this method also appends a cause to
378 * the error of the current thread using the same message.
379 */
380 template <Level LevelV, bool AppendCauseV, typename... ArgTs>
381 void logErrno(const char * const fileName, const char * const funcName,
382 const unsigned int lineNo, const char * const initMsg, const char * const fmt,
383 ArgTs&&...args) const
384 {
385 this->_log<_InitMsgLogWriter, LevelV, AppendCauseV>(fileName, funcName, lineNo, nullptr, 0,
386 this->_errnoIntroStr(initMsg).c_str(),
387 fmt, std::forward<ArgTs>(args)...);
388 }
389
390 /*
391 * Logs the message of `errno` using the level `LevelV`.
392 *
393 * The log message starts with `initMsg`, is followed with the
394 * message for `errno`, and then with `msg`.
395 *
396 * If `AppendCauseV` is true, this method also appends a cause to
397 * the error of the current thread using the same message.
398 */
399 template <Level LevelV, bool AppendCauseV>
400 void logErrnoStr(const char * const fileName, const char * const funcName,
401 const unsigned int lineNo, const char * const initMsg,
402 const char * const msg) const
403 {
404 this->_logStr<_InitMsgLogWriter, LevelV, AppendCauseV>(
405 fileName, funcName, lineNo, nullptr, 0, this->_errnoIntroStr(initMsg).c_str(), msg);
406 }
407
408 /*
409 * Like logErrno() with the `Level::Error` level, but also throws a
410 * default-constructed instance of `ExcT`.
411 */
412 template <bool AppendCauseV, typename ExcT, typename... ArgTs>
413 [[noreturn]] void logErrorErrnoAndThrow(const char * const fileName,
414 const char * const funcName, const unsigned int lineNo,
415 const char * const initMsg, const char * const fmt,
416 ArgTs&&...args) const
417 {
418 this->logErrno<Level::Error, AppendCauseV>(fileName, funcName, lineNo, initMsg, fmt,
419 std::forward<ArgTs>(args)...);
420 throw ExcT {};
421 }
422
423 /*
424 * Like logErrnoStr() with the `Level::Error` level, but also throws
425 * a default-constructed instance of `ExcT`.
426 */
427 template <bool AppendCauseV, typename ExcT>
428 [[noreturn]] void
429 logErrorErrnoStrAndThrow(const char * const fileName, const char * const funcName,
430 const unsigned int lineNo, const char * const initMsg,
431 const char * const msg) const
432 {
433 this->logErrnoStr<Level::Error, AppendCauseV>(fileName, funcName, lineNo, initMsg, msg);
434 throw ExcT {};
435 }
436
437 /*
438 * Like logErrno() with the `Level::Error` level, but also rethrows.
439 */
440 template <bool AppendCauseV, typename... ArgTs>
441 [[noreturn]] void logErrorErrnoAndRethrow(const char * const fileName,
442 const char * const funcName,
443 const unsigned int lineNo, const char * const initMsg,
444 const char * const fmt, ArgTs&&...args) const
445 {
446 this->logErrno<Level::Error, AppendCauseV>(fileName, funcName, lineNo, initMsg, fmt,
447 std::forward<ArgTs>(args)...);
448 throw;
449 }
450
451 /*
452 * Like logErrnoStr() with the `Level::Error` level, but also
453 * rethrows.
454 */
455 template <bool AppendCauseV>
456 [[noreturn]] void
457 logErrorErrnoStrAndRethrow(const char * const fileName, const char * const funcName,
458 const unsigned int lineNo, const char * const initMsg,
459 const char * const msg) const
460 {
461 this->logErrnoStr<Level::Error, AppendCauseV>(fileName, funcName, lineNo, initMsg, msg);
462 throw;
463 }
464
465 private:
466 struct _MemLogWriter final
467 {
468 static void write(const char * const fileName, const char * const funcName,
469 const unsigned lineNo, const Level level, const char * const tag,
470 const void * const memData, const unsigned int memLen, const char *,
471 const char * const msg) noexcept
472 {
473 bt_log_write_mem(funcName, fileName, lineNo, static_cast<bt_log_level>(level), tag,
474 memData, memLen, msg);
475 }
476 };
477
478 public:
479 /*
480 * Logs memory data using the level `LevelV`.
481 *
482 * This method forwards `fmt` and `args` to fmt::format() to create
483 * the log message.
484 */
485 template <Level LevelV, typename... ArgTs>
486 void logMem(const char * const fileName, const char * const funcName, const unsigned int lineNo,
487 const void * const memData, const unsigned int memLen, const char * const fmt,
488 ArgTs&&...args) const
489 {
490 this->_log<_MemLogWriter, LevelV, false>(fileName, funcName, lineNo, memData, memLen, "",
491 fmt, std::forward<ArgTs>(args)...);
492 }
493
494 /*
495 * Logs memory data using the level `LevelV`, starting with the
496 * message `msg`.
497 */
498 template <Level LevelV>
499 void logMemStr(const char * const fileName, const char * const funcName,
500 const unsigned int lineNo, const void * const memData, const unsigned int memLen,
501 const char * const msg) const
502 {
503 this->_logStr<_MemLogWriter, LevelV, false>(fileName, funcName, lineNo, memData, memLen, "",
504 msg);
505 }
506
507 private:
508 /*
509 * Formats a log message with fmt::format() given `fmt` and `args`,
510 * and then forwards everything to _logStr().
511 */
512 template <typename LogWriterT, Level LevelV, bool AppendCauseV, typename... ArgTs>
513 void _log(const char * const fileName, const char * const funcName, const unsigned int lineNo,
514 const void * const memData, const std::size_t memLen, const char * const initMsg,
515 const char * const fmt, ArgTs&&...args) const
516 {
517 /* Only format arguments if logging or appending an error cause */
518 if (G_UNLIKELY(this->wouldLog(LevelV) || AppendCauseV)) {
519 /*
520 * Format arguments to our buffer (fmt::format_to() doesn't
521 * append a null character).
522 */
523 _mBuf.clear();
524 fmt::format_to(std::back_inserter(_mBuf), fmt, std::forward<ArgTs>(args)...);
525 _mBuf.push_back('\0');
526 }
527
528 this->_logStr<LogWriterT, LevelV, AppendCauseV>(fileName, funcName, lineNo, memData, memLen,
529 initMsg, _mBuf.data());
530 }
531
532 /*
533 * Calls LogWriterT::write() with its arguments to log using the
534 * level `LevelV`.
535 *
536 * If `AppendCauseV` is true, this method also appends a cause to
537 * the error of the current thread using the concatenation of
538 * `initMsg` and `msg` as the message.
539 */
540 template <typename LogWriterT, Level LevelV, bool AppendCauseV>
541 void _logStr(const char * const fileName, const char * const funcName,
542 const unsigned int lineNo, const void * const memData, const std::size_t memLen,
543 const char * const initMsg, const char * const msg) const
544 {
545 /* Initial message and main message are required */
546 BT_ASSERT(initMsg);
547 BT_ASSERT(msg);
548
549 /* Log if needed */
550 if (this->wouldLog(LevelV)) {
551 LogWriterT::write(fileName, funcName, lineNo, LevelV, _mTag.data(), memData, memLen,
552 initMsg, msg);
553 }
554
555 /* Append an error cause if needed */
556 if (AppendCauseV) {
557 if (_mSelfMsgIter) {
558 bt_current_thread_error_append_cause_from_message_iterator(
559 _mSelfMsgIter->libObjPtr(), fileName, lineNo, "%s%s", initMsg, msg);
560 } else if (_mSelfComp) {
561 bt_current_thread_error_append_cause_from_component(
562 _mSelfComp->libObjPtr(), fileName, lineNo, "%s%s", initMsg, msg);
563 } else if (_mSelfCompCls) {
564 bt_current_thread_error_append_cause_from_component_class(
565 _mSelfCompCls->libObjPtr(), fileName, lineNo, "%s%s", initMsg, msg);
566 } else {
567 BT_ASSERT(_mModuleName);
568 bt_current_thread_error_append_cause_from_unknown(_mModuleName->data(), fileName,
569 lineNo, "%s%s", initMsg, msg);
570 }
571 }
572 }
573
574 static std::string _errnoIntroStr(const char * const initMsg)
575 {
576 BT_ASSERT(errno != 0);
577 return fmt::format("{}: {}", initMsg, g_strerror(errno));
578 }
579
580 /* Exactly one of the following four members has a value */
581 bt2s::optional<bt2::SelfComponentClass> _mSelfCompCls;
582 bt2s::optional<bt2::SelfComponent> _mSelfComp;
583 bt2s::optional<bt2::SelfMessageIterator> _mSelfMsgIter;
584 bt2s::optional<std::string> _mModuleName;
585
586 /* Current logging level */
587 Level _mLevel;
588
589 /* Logging tag */
590 std::string _mTag;
591
592 /* Formatting buffer */
593 mutable std::vector<char> _mBuf;
594 };
595
596 /*
597 * Returns `s` if it's not `nullptr`, or the `(null)` string otherwise.
598 */
599 inline const char *maybeNull(const char * const s) noexcept
600 {
601 return s ? s : "(null)";
602 }
603
604 } /* namespace bt2c */
605
606 /* Internal: default logger name */
607 #define _BT_CPPLOG_DEF_LOGGER _mLogger
608
609 /*
610 * Calls log() on `_logger` to log using the level `_lvl`.
611 */
612 #define BT_CPPLOG_EX(_lvl, _logger, _fmt, ...) \
613 do { \
614 if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \
615 (_logger).log<(_lvl), false>(__FILE__, __func__, __LINE__, (_fmt), ##__VA_ARGS__); \
616 } \
617 } while (0)
618
619 /*
620 * BT_CPPLOG_EX() with specific logging levels.
621 */
622 #define BT_CPPLOGT_SPEC(_logger, _fmt, ...) \
623 BT_CPPLOG_EX(bt2c::Logger::Level::Trace, (_logger), (_fmt), ##__VA_ARGS__)
624 #define BT_CPPLOGD_SPEC(_logger, _fmt, ...) \
625 BT_CPPLOG_EX(bt2c::Logger::Level::Debug, (_logger), (_fmt), ##__VA_ARGS__)
626 #define BT_CPPLOGI_SPEC(_logger, _fmt, ...) \
627 BT_CPPLOG_EX(bt2c::Logger::Level::Info, (_logger), (_fmt), ##__VA_ARGS__)
628 #define BT_CPPLOGW_SPEC(_logger, _fmt, ...) \
629 BT_CPPLOG_EX(bt2c::Logger::Level::Warning, (_logger), (_fmt), ##__VA_ARGS__)
630 #define BT_CPPLOGE_SPEC(_logger, _fmt, ...) \
631 BT_CPPLOG_EX(bt2c::Logger::Level::Error, (_logger), (_fmt), ##__VA_ARGS__)
632 #define BT_CPPLOGF_SPEC(_logger, _fmt, ...) \
633 BT_CPPLOG_EX(bt2c::Logger::Level::Fatal, (_logger), (_fmt), ##__VA_ARGS__)
634
635 /*
636 * BT_CPPLOG_EX() with specific logging levels and using the default
637 * logger.
638 */
639 #define BT_CPPLOGT(_fmt, ...) BT_CPPLOGT_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
640 #define BT_CPPLOGD(_fmt, ...) BT_CPPLOGD_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
641 #define BT_CPPLOGI(_fmt, ...) BT_CPPLOGI_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
642 #define BT_CPPLOGW(_fmt, ...) BT_CPPLOGW_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
643 #define BT_CPPLOGE(_fmt, ...) BT_CPPLOGE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
644 #define BT_CPPLOGF(_fmt, ...) BT_CPPLOGF_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
645
646 /*
647 * Calls logStr() on `_logger` to log using the level `_lvl`.
648 */
649 #define BT_CPPLOG_STR_EX(_lvl, _logger, _msg) \
650 (_logger).logStr<(_lvl), false>(__FILE__, __func__, __LINE__, (_msg))
651
652 /*
653 * BT_CPPLOG_STR_EX() with specific logging levels.
654 */
655 #define BT_CPPLOGT_STR_SPEC(_logger, _msg) \
656 BT_CPPLOG_STR_EX(bt2c::Logger::Level::Trace, (_logger), (_msg))
657 #define BT_CPPLOGD_STR_SPEC(_logger, _msg) \
658 BT_CPPLOG_STR_EX(bt2c::Logger::Level::Debug, (_logger), (_msg))
659 #define BT_CPPLOGI_STR_SPEC(_logger, _msg) \
660 BT_CPPLOG_STR_EX(bt2c::Logger::Level::Info, (_logger), (_msg))
661 #define BT_CPPLOGW_STR_SPEC(_logger, _msg) \
662 BT_CPPLOG_STR_EX(bt2c::Logger::Level::Warning, (_logger), (_msg))
663 #define BT_CPPLOGE_STR_SPEC(_logger, _msg) \
664 BT_CPPLOG_STR_EX(bt2c::Logger::Level::Error, (_logger), (_msg))
665 #define BT_CPPLOGF_STR_SPEC(_logger, _msg) \
666 BT_CPPLOG_STR_EX(bt2c::Logger::Level::Fatal, (_logger), (_msg))
667
668 /*
669 * BT_CPPLOG_STR_EX() with specific logging levels and using the default
670 * logger.
671 */
672 #define BT_CPPLOGT_STR(_msg) BT_CPPLOGT_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_msg))
673 #define BT_CPPLOGD_STR(_msg) BT_CPPLOGD_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_msg))
674 #define BT_CPPLOGI_STR(_msg) BT_CPPLOGI_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_msg))
675 #define BT_CPPLOGW_STR(_msg) BT_CPPLOGW_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_msg))
676 #define BT_CPPLOGE_STR(_msg) BT_CPPLOGE_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_msg))
677 #define BT_CPPLOGF_STR(_msg) BT_CPPLOGF_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_msg))
678
679 /*
680 * Calls logMem() on `_logger` to log using the level `_lvl`.
681 */
682 #define BT_CPPLOG_MEM_EX(_lvl, _logger, _mem_data, _mem_len, _fmt, ...) \
683 do { \
684 if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \
685 (_logger).logMem<(_lvl)>(__FILE__, __func__, __LINE__, (_mem_data), (_mem_len), \
686 (_fmt), ##__VA_ARGS__); \
687 } \
688 } while (0)
689
690 /*
691 * BT_CPPLOG_MEM_EX() with specific logging levels.
692 */
693 #define BT_CPPLOGT_MEM_SPEC(_logger, _mem_data, _mem_len, _fmt, ...) \
694 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Trace, (_logger), (_mem_data), (_mem_len), (_fmt), \
695 ##__VA_ARGS__)
696 #define BT_CPPLOGD_MEM_SPEC(_logger, _mem_data, _mem_len, _fmt, ...) \
697 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Debug, (_logger), (_mem_data), (_mem_len), (_fmt), \
698 ##__VA_ARGS__)
699 #define BT_CPPLOGI_MEM_SPEC(_logger, _mem_data, _mem_len, _fmt, ...) \
700 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Info, (_logger), (_mem_data), (_mem_len), (_fmt), \
701 ##__VA_ARGS__)
702 #define BT_CPPLOGW_MEM_SPEC(_logger, _mem_data, _mem_len, _fmt, ...) \
703 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Warning, (_logger), (_mem_data), (_mem_len), (_fmt), \
704 ##__VA_ARGS__)
705 #define BT_CPPLOGE_MEM_SPEC(_logger, _mem_data, _mem_len, _fmt, ...) \
706 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Error, (_logger), (_mem_data), (_mem_len), (_fmt), \
707 ##__VA_ARGS__)
708 #define BT_CPPLOGF_MEM_SPEC(_logger, _mem_data, _mem_len, _fmt, ...) \
709 BT_CPPLOG_MEM_EX(bt2c::Logger::Level::Fatal, (_logger), (_mem_data), (_mem_len), (_fmt), \
710 ##__VA_ARGS__)
711
712 /*
713 * BT_CPPLOG_MEM_EX() with specific logging levels and using the default
714 * logger.
715 */
716 #define BT_CPPLOGT_MEM(_mem_data, _mem_len, _fmt, ...) \
717 BT_CPPLOGT_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_fmt), ##__VA_ARGS__)
718 #define BT_CPPLOGD_MEM(_mem_data, _mem_len, _fmt, ...) \
719 BT_CPPLOGD_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_fmt), ##__VA_ARGS__)
720 #define BT_CPPLOGI_MEM(_mem_data, _mem_len, _fmt, ...) \
721 BT_CPPLOGI_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_fmt), ##__VA_ARGS__)
722 #define BT_CPPLOGW_MEM(_mem_data, _mem_len, _fmt, ...) \
723 BT_CPPLOGW_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_fmt), ##__VA_ARGS__)
724 #define BT_CPPLOGE_MEM(_mem_data, _mem_len, _fmt, ...) \
725 BT_CPPLOGE_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_fmt), ##__VA_ARGS__)
726 #define BT_CPPLOGF_MEM(_mem_data, _mem_len, _fmt, ...) \
727 BT_CPPLOGF_MEM_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_fmt), ##__VA_ARGS__)
728
729 /*
730 * Calls logMemStr() on `_logger` to log using the level `_lvl`.
731 */
732 #define BT_CPPLOG_MEM_STR_EX(_lvl, _logger, _mem_data, _mem_len, _msg) \
733 (_logger).logMemStr<(_lvl)>(__FILE__, __func__, __LINE__, (_mem_data), (_mem_len), (_msg))
734
735 /*
736 * BT_CPPLOG_MEM_STR_EX() with specific logging levels.
737 */
738 #define BT_CPPLOGT_MEM_STR_SPEC(_logger, _mem_data, _mem_len, _msg) \
739 BT_CPPLOG_MEM_STR_EX(bt2c::Logger::Level::TRACE, (_logger), (_mem_data), (_mem_len), (_msg))
740 #define BT_CPPLOGD_MEM_STR_SPEC(_logger, _mem_data, _mem_len, _msg) \
741 BT_CPPLOG_MEM_STR_EX(bt2c::Logger::Level::DEBUG, (_logger), (_mem_data), (_mem_len), (_msg))
742 #define BT_CPPLOGI_MEM_STR_SPEC(_logger, _mem_data, _mem_len, _msg) \
743 BT_CPPLOG_MEM_STR_EX(bt2c::Logger::Level::INFO, (_logger), (_mem_data), (_mem_len), (_msg))
744 #define BT_CPPLOGW_MEM_STR_SPEC(_logger, _mem_data, _mem_len, _msg) \
745 BT_CPPLOG_MEM_STR_EX(bt2c::Logger::Level::WARNING, (_logger), (_mem_data), (_mem_len), (_msg))
746 #define BT_CPPLOGE_MEM_STR_SPEC(_logger, _mem_data, _mem_len, _msg) \
747 BT_CPPLOG_MEM_STR_EX(bt2c::Logger::Level::Error, (_logger), (_mem_data), (_mem_len), (_msg))
748 #define BT_CPPLOGF_MEM_STR_SPEC(_logger, _mem_data, _mem_len, _msg) \
749 BT_CPPLOG_MEM_STR_EX(bt2c::Logger::Level::FATAL, (_logger), (_mem_data), (_mem_len), (_msg))
750
751 /*
752 * BT_CPPLOG_MEM_STR_EX() with specific logging levels and using the
753 * default logger.
754 */
755 #define BT_CPPLOGT_MEM_STR(_mem_data, _mem_len, _msg) \
756 BT_CPPLOGT_MEM_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_msg))
757 #define BT_CPPLOGD_MEM_STR(_mem_data, _mem_len, _msg) \
758 BT_CPPLOGD_MEM_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_msg))
759 #define BT_CPPLOGI_MEM_STR(_mem_data, _mem_len, _msg) \
760 BT_CPPLOGI_MEM_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_msg))
761 #define BT_CPPLOGW_MEM_STR(_mem_data, _mem_len, _msg) \
762 BT_CPPLOGW_MEM_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_msg))
763 #define BT_CPPLOGE_MEM_STR(_mem_data, _mem_len, _msg) \
764 BT_CPPLOGE_MEM_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_msg))
765 #define BT_CPPLOGF_MEM_STR(_mem_data, _mem_len, _msg) \
766 BT_CPPLOGF_MEM_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_mem_data), (_mem_len), (_msg))
767
768 /*
769 * Calls logErrno() on `_logger` to log using the level `_lvl` and
770 * initial message `_init_msg`.
771 */
772 #define BT_CPPLOG_ERRNO_EX(_lvl, _logger, _init_msg, _fmt, ...) \
773 do { \
774 if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \
775 (_logger).logErrno<(_lvl), false>(__FILE__, __func__, __LINE__, (_init_msg), (_fmt), \
776 ##__VA_ARGS__); \
777 } \
778 } while (0)
779
780 /*
781 * BT_CPPLOG_ERRNO_EX() with specific logging levels.
782 */
783 #define BT_CPPLOGT_ERRNO_SPEC(_logger, _init_msg, _fmt, ...) \
784 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Trace, (_logger), (_init_msg), (_fmt), ##__VA_ARGS__)
785 #define BT_CPPLOGD_ERRNO_SPEC(_logger, _init_msg, _fmt, ...) \
786 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Debug, (_logger), (_init_msg), (_fmt), ##__VA_ARGS__)
787 #define BT_CPPLOGI_ERRNO_SPEC(_logger, _init_msg, _fmt, ...) \
788 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Info, (_logger), (_init_msg), (_fmt), ##__VA_ARGS__)
789 #define BT_CPPLOGW_ERRNO_SPEC(_logger, _init_msg, _fmt, ...) \
790 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Warning, (_logger), (_init_msg), (_fmt), ##__VA_ARGS__)
791 #define BT_CPPLOGE_ERRNO_SPEC(_logger, _init_msg, _fmt, ...) \
792 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Error, (_logger), (_init_msg), (_fmt), ##__VA_ARGS__)
793 #define BT_CPPLOGF_ERRNO_SPEC(_logger, _init_msg, _fmt, ...) \
794 BT_CPPLOG_ERRNO_EX(bt2c::Logger::Level::Fatal, (_logger), (_init_msg), (_fmt), ##__VA_ARGS__)
795
796 /*
797 * BT_CPPLOG_ERRNO_EX() with specific logging levels and using the
798 * default logger.
799 */
800 #define BT_CPPLOGT_ERRNO(_init_msg, _fmt, ...) \
801 BT_CPPLOGT_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_fmt), ##__VA_ARGS__)
802 #define BT_CPPLOGD_ERRNO(_init_msg, _fmt, ...) \
803 BT_CPPLOGD_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_fmt), ##__VA_ARGS__)
804 #define BT_CPPLOGI_ERRNO(_init_msg, _fmt, ...) \
805 BT_CPPLOGI_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_fmt), ##__VA_ARGS__)
806 #define BT_CPPLOGW_ERRNO(_init_msg, _fmt, ...) \
807 BT_CPPLOGW_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_fmt), ##__VA_ARGS__)
808 #define BT_CPPLOGE_ERRNO(_init_msg, _fmt, ...) \
809 BT_CPPLOGE_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_fmt), ##__VA_ARGS__)
810 #define BT_CPPLOGF_ERRNO(_init_msg, _fmt, ...) \
811 BT_CPPLOGF_ERRNO_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_fmt), ##__VA_ARGS__)
812
813 /*
814 * Calls logErrnoStr() on `_logger` to log using the level `_lvl` and
815 * initial message `_init_msg`.
816 */
817 #define BT_CPPLOG_ERRNO_STR_EX(_lvl, _logger, _init_msg, _msg) \
818 (_logger).logErrnoStr<(_lvl), false>(__FILE__, __func__, __LINE__, (_init_msg), (_msg))
819
820 /*
821 * BT_CPPLOG_ERRNO_STR_EX() with specific logging levels.
822 */
823 #define BT_CPPLOGT_ERRNO_STR_SPEC(_logger, _init_msg, _msg) \
824 BT_CPPLOG_ERRNO_STR_EX(bt2c::Logger::Level::Trace, (_logger), (_init_msg), (_msg))
825 #define BT_CPPLOGD_ERRNO_STR_SPEC(_logger, _init_msg, _msg) \
826 BT_CPPLOG_ERRNO_STR_EX(bt2c::Logger::Level::Debug, (_logger), (_init_msg), (_msg))
827 #define BT_CPPLOGI_ERRNO_STR_SPEC(_logger, _init_msg, _msg) \
828 BT_CPPLOG_ERRNO_STR_EX(bt2c::Logger::Level::Info, (_logger), (_init_msg), (_msg))
829 #define BT_CPPLOGW_ERRNO_STR_SPEC(_logger, _init_msg, _msg) \
830 BT_CPPLOG_ERRNO_STR_EX(bt2c::Logger::Level::Warning, (_logger), (_init_msg), (_msg))
831 #define BT_CPPLOGE_ERRNO_STR_SPEC(_logger, _init_msg, _msg) \
832 BT_CPPLOG_ERRNO_STR_EX(bt2c::Logger::Level::Error, (_logger), (_init_msg), (_msg))
833 #define BT_CPPLOGF_ERRNO_STR_SPEC(_logger, _init_msg, _msg) \
834 BT_CPPLOG_ERRNO_STR_EX(bt2c::Logger::Level::Fatal, (_logger), (_init_msg), (_msg))
835
836 /*
837 * BT_CPPLOG_ERRNO_STR_EX() with specific logging levels and using the
838 * default logger.
839 */
840 #define BT_CPPLOGT_ERRNO_STR(_init_msg, _msg) \
841 BT_CPPLOGT_ERRNO_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_msg))
842 #define BT_CPPLOGD_ERRNO_STR(_init_msg, _msg) \
843 BT_CPPLOGD_ERRNO_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_msg))
844 #define BT_CPPLOGI_ERRNO_STR(_init_msg, _msg) \
845 BT_CPPLOGI_ERRNO_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_msg))
846 #define BT_CPPLOGW_ERRNO_STR(_init_msg, _msg) \
847 BT_CPPLOGW_ERRNO_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_msg))
848 #define BT_CPPLOGE_ERRNO_STR(_init_msg, _msg) \
849 BT_CPPLOGE_ERRNO_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_msg))
850 #define BT_CPPLOGF_ERRNO_STR(_init_msg, _msg) \
851 BT_CPPLOGF_ERRNO_STR_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_msg))
852
853 /*
854 * Calls log() on `_logger` with the `Error` level to log an error and
855 * append a cause to the error of the current thread.
856 */
857 #define BT_CPPLOGE_APPEND_CAUSE_SPEC(_logger, _fmt, ...) \
858 (_logger).log<bt2c::Logger::Level::Error, true>(__FILE__, __func__, __LINE__, (_fmt), \
859 ##__VA_ARGS__)
860
861 /*
862 * BT_CPPLOGE_APPEND_CAUSE_SPEC() using the default logger.
863 */
864 #define BT_CPPLOGE_APPEND_CAUSE(_fmt, ...) \
865 BT_CPPLOGE_APPEND_CAUSE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
866
867 /*
868 * Calls logStr() on `_logger` with the `Error` level to log an error and
869 * append a cause to the error of the current thread.
870 */
871 #define BT_CPPLOGE_STR_APPEND_CAUSE_SPEC(_logger, _msg) \
872 (_logger).logStr<bt2c::Logger::Level::Error, true>(__FILE__, __func__, __LINE__, (_msg))
873
874 /*
875 * BT_CPPLOGE_STR_APPEND_CAUSE_SPEC() using the default logger.
876 */
877 #define BT_CPPLOGE_STR_APPEND_CAUSE(_msg) \
878 BT_CPPLOGE_STR_APPEND_CAUSE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_msg))
879
880 /*
881 * Calls logErrorAndThrow() on `_logger` to log an error, append a cause
882 * to the error of the current thread, and throw an instance of
883 * `_exc_cls`.
884 */
885 #define BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(_logger, _exc_cls, _fmt, ...) \
886 (_logger).logErrorAndThrow<true, _exc_cls>(__FILE__, __func__, __LINE__, (_fmt), ##__VA_ARGS__)
887
888 /*
889 * BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC() using the default logger.
890 */
891 #define BT_CPPLOGE_APPEND_CAUSE_AND_THROW(_exc_cls, _fmt, ...) \
892 BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(_BT_CPPLOG_DEF_LOGGER, _exc_cls, (_fmt), ##__VA_ARGS__)
893
894 /*
895 * Calls logErrorStrAndThrow() on `_logger` to log an error, append a
896 * cause to the error of the current thread, and throw an instance of
897 * `_exc_cls`.
898 */
899 #define BT_CPPLOGE_STR_APPEND_CAUSE_AND_THROW_SPEC(_logger, _exc_cls, _msg) \
900 (_logger).logErrorStrAndThrow<true, _exc_cls>(__FILE__, __func__, __LINE__, (_msg))
901
902 /*
903 * BT_CPPLOGE_STR_APPEND_CAUSE_AND_THROW_SPEC() using the default
904 * logger.
905 */
906 #define BT_CPPLOGE_STR_APPEND_CAUSE_AND_THROW(_exc_cls, _msg) \
907 BT_CPPLOGE_STR_APPEND_CAUSE_AND_THROW_SPEC(_BT_CPPLOG_DEF_LOGGER, _exc_cls, (_msg))
908
909 /*
910 * Calls logErrorAndRethrow() on `_logger` to log an error, append a
911 * cause to the error of the current thread, and throw an instance of
912 * `_exc_cls`.
913 */
914 #define BT_CPPLOGE_APPEND_CAUSE_AND_RETHROW_SPEC(_logger, _fmt, ...) \
915 (_logger).logErrorAndRethrow<true>(__FILE__, __func__, __LINE__, (_fmt), ##__VA_ARGS__)
916
917 /*
918 * BT_CPPLOGE_APPEND_CAUSE_AND_RETHROW_SPEC() using the default logger.
919 */
920 #define BT_CPPLOGE_APPEND_CAUSE_AND_RETHROW(_fmt, ...) \
921 BT_CPPLOGE_APPEND_CAUSE_AND_RETHROW_SPEC(_BT_CPPLOG_DEF_LOGGER, (_fmt), ##__VA_ARGS__)
922
923 /*
924 * Calls logErrorStrAndRethrow() on `_logger` to log an error, append a
925 * cause to the error of the current thread, and throw an instance of
926 * `_exc_cls`.
927 */
928 #define BT_CPPLOGE_STR_APPEND_CAUSE_AND_RETHROW_SPEC(_logger, _msg) \
929 (_logger).logErrorStrAndRethrow<true>(__FILE__, __func__, __LINE__, (_msg))
930
931 /*
932 * BT_CPPLOGE_STR_APPEND_CAUSE_AND_RETHROW_SPEC() using the default
933 * logger.
934 */
935 #define BT_CPPLOGE_STR_APPEND_CAUSE_AND_RETHROW(_msg) \
936 BT_CPPLOGE_STR_APPEND_CAUSE_AND_RETHROW_SPEC(_BT_CPPLOG_DEF_LOGGER, (_msg))
937
938 /*
939 * Calls logErrno() on `_logger` with the `Level::Error` level to log an
940 * error and append a cause to the error of the current thread.
941 */
942 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(_logger, _init_msg, _fmt, ...) \
943 (_logger).logErrno<bt2c::Logger::Level::Error, true>(__FILE__, __func__, __LINE__, \
944 (_init_msg), (_fmt), ##__VA_ARGS__)
945
946 /*
947 * BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC() using the default logger.
948 */
949 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE(_init_msg, _fmt, ...) \
950 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_fmt), ##__VA_ARGS__)
951
952 /*
953 * Calls logErrnoStr() on `_logger` with the `Level::Error` level to log
954 * an error and append a cause to the error of the current thread.
955 */
956 #define BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_SPEC(_logger, _init_msg, _msg) \
957 (_logger).logErrnoStr<bt2c::Logger::Level::Error, true>(__FILE__, __func__, __LINE__, \
958 (_init_msg), (_msg))
959
960 /*
961 * BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_SPEC() using the default logger.
962 */
963 #define BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE(_init_msg, _msg) \
964 BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_msg))
965
966 /*
967 * Calls logErrorErrnoAndThrow() on `_logger` to log an error, append a
968 * cause to the error of the current thread, and throw an instance of
969 * `_exc_cls`.
970 */
971 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_THROW_SPEC(_logger, _exc_cls, _init_msg, _fmt, ...) \
972 (_logger).logErrorErrnoAndThrow<true, _exc_cls>(__FILE__, __func__, __LINE__, (_init_msg), \
973 (_fmt), ##__VA_ARGS__)
974
975 /*
976 * BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_THROW_SPEC() using the default
977 * logger.
978 */
979 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_THROW(_exc_cls, _init_msg, _fmt, ...) \
980 BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_THROW_SPEC(_BT_CPPLOG_DEF_LOGGER, _exc_cls, (_init_msg), \
981 (_fmt), ##__VA_ARGS__)
982
983 /*
984 * Calls logErrorErrnoStrAndThrow() on `_logger` to log an error, append
985 * a cause to the error of the current thread, and throw an instance of
986 * `_exc_cls`.
987 */
988 #define BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_THROW_SPEC(_logger, _exc_cls, _init_msg, _msg) \
989 (_logger).logErrorErrnoStrAndThrow<true, _exc_cls>(__FILE__, __func__, __LINE__, (_init_msg), \
990 (_msg))
991
992 /*
993 * BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_THROW_SPEC() using the default
994 * logger.
995 */
996 #define BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_THROW(_exc_cls, _init_msg, _msg) \
997 BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_THROW_SPEC(_BT_CPPLOG_DEF_LOGGER, _exc_cls, (_init_msg), \
998 (_msg))
999
1000 /*
1001 * Calls logErrorErrnoAndRethrow() on `_logger` to log an error, append
1002 * a cause to the error of the current thread, and throw an instance of
1003 * `_exc_cls`.
1004 */
1005 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_SPEC(_logger, _init_msg, _fmt, ...) \
1006 (_logger).logErrorErrnoAndRethrow<true>(__FILE__, __func__, __LINE__, (_init_msg), (_fmt), \
1007 ##__VA_ARGS__)
1008
1009 /*
1010 * BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_SPEC() using the default
1011 * logger.
1012 */
1013 #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW(_init_msg, _fmt, ...) \
1014 BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_fmt), \
1015 ##__VA_ARGS__)
1016
1017 /*
1018 * Calls logErrorErrnoStrAndRethrow() on `_logger` to log an error,
1019 * append a cause to the error of the current thread, and throw an
1020 * instance of `_exc_cls`.
1021 */
1022 #define BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_RETHROW_SPEC(_logger, _init_msg, _msg) \
1023 (_logger).logErrorErrnoStrAndRethrow<true>(__FILE__, __func__, __LINE__, (_init_msg), (_msg))
1024
1025 /*
1026 * BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_RETHROW_SPEC() using the
1027 * default logger.
1028 */
1029 #define BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_RETHROW(_init_msg, _msg) \
1030 BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_RETHROW_SPEC(_BT_CPPLOG_DEF_LOGGER, (_init_msg), (_msg))
1031
1032 #endif /* BABELTRACE_CPP_COMMON_BT2C_LOGGING_HPP */
This page took 0.055281 seconds and 4 git commands to generate.