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