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