src/cpp-common: add BT_APPEND_CAUSE*() and BT_CLOG_*() macros
This patch adds the following files:
`src/cpp-common/cfg-logging.hpp`:
Offers the following macros:
BT_CLOG*_EX():
Logs using a given logging configuration reference.
BT_CLOG*_STR_EX():
Logs a literal string using a given logging configuration
reference.
BT_CLOG*_ERRNO_EX():
Logs an errno message using a given logging configuration
reference.
BT_CLOG*_MEM_EX():
Logs memory bytes using a given logging configuration reference.
All the macros above also have their variant without the `_EX`
suffix which uses the logging configuration reference `BT_CLOG_CFG`.
Those macros decide, depending on what's available within the
provided logging configuration object, how to prefix the complete
log message.
`src/cpp-common/cfg-error-reporting.hpp`:
Offers the following macros:
BT_APPEND_CAUSE_EX():
BT_APPEND_CAUSE_STR_EX():
BT_APPEND_CAUSE_ERRNO_EX():
Appends a cause to the error of the current thread using a given
logging configuration reference.
All the macros above also have their variant without the `_EX`
suffix which uses the logging configuration reference `BT_CLOG_CFG`.
Those macros decide, depending on what's available within the
provided logging configuration object, which
BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_*() macro to use.
`src/cpp-common/cfg-error-reporting-throw.hpp`:
Offers the following macros:
BT_APPEND_CAUSE_AND_THROW_EX():
Appends a cause to the error of the current thread using a given
logging configuration reference, and throws an exception.
BT_APPEND_CAUSE_AND_RETHROW_EX():
Appends a cause to the error of the current thread using a given
logging configuration reference, and rethrows.
BT_STR_APPEND_CAUSE_AND_THROW_EX():
Appends a cause to the error of the current thread using a given
logging configuration reference, and throws an exception.
BT_STR_APPEND_CAUSE_AND_RETHROW_EX():
Appends a cause to the error of the current thread using a given
logging configuration reference, and rethrows.
BT_ERRNO_APPEND_CAUSE_AND_THROW_EX():
Appends a cause with an errno message to the error of the
current thread using a given logging configuration reference,
and throws an exception.
BT_ERRNO_APPEND_CAUSE_AND_RETHROW_EX():
Appends a cause with an errno message to the error of the
current thread using a given logging configuration reference,
and rethrows.
All the macros above also have their variant without the `_EX`
suffix which uses the logging configuration reference `BT_CLOG_CFG`.
`src/cpp-common/cfg-logging-error-reporting.hpp`:
Offers the following macros:
BT_CLOGE_APPEND_CAUSE_EX():
Logs using a given logging configuration reference and appends
a cause to the error of the current thread.
BT_CLOGE_STR_APPEND_CAUSE_EX():
Logs a literal string using a given logging configuration
reference and appends a cause to the error of the current
thread.
BT_CLOGE_ERRNO_APPEND_CAUSE_EX():
Logs an errno message using a given logging configuration
reference and appends a cause to the error of the current
thread.
BT_CLOGE_MEM_APPEND_CAUSE_EX():
Logs memory bytes using a given logging configuration reference
and appends a cause to the error of the current thread.
All the macros above also have their variant without the `_EX`
suffix which uses the logging configuration reference `BT_CLOG_CFG`.
Those macros decide, depending on what's available within the
provided logging configuration object, which
BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_*() macro to use.
`src/cpp-common/cfg-logging-error-reporting-throw.hpp`:
Offers the following macros:
BT_CLOGE_APPEND_CAUSE_AND_THROW_EX():
Logs using a given logging configuration reference, appends a
cause to the error of the current thread, and throws an
exception.
BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX():
Logs using a given logging configuration reference, appends a
cause to the error of the current thread, and rethrows.
BT_CLOGE_STR_APPEND_CAUSE_AND_THROW_EX():
Logs a literal string using a given logging configuration
reference, appends a cause to the error of the current thread,
and throws an exception.
BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW_EX():
Logs a literal string using a given logging configuration
reference, appends a cause to the error of the current thread,
and rethrows.
BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX():
Logs an errno message using a given logging configuration
reference, appends a cause to the error of the current thread,
and throws an exception.
BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX():
Logs an errno message using a given logging configuration
reference, appends a cause to the error of the current thread,
and rethrows.
BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX():
Logs memory bytes using a given logging configuration reference,
appends a cause to the error of the current thread, and throws
an exception.
BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX():
Logs memory bytes using a given logging configuration reference,
appends a cause to the error of the current thread, and
rethrows.
All the macros above also have their variant without the `_EX`
suffix which uses the logging configuration reference `BT_CLOG_CFG`.
The intended usage is as such:
1. In a header file defining a class, have a logging configuration
member:
bt2_common::LogCfg _mLogCfg;
Make the constructor of the class accept a logging configuration
reference and copy it to `_mLogCfg`.
2. In the source file which implements the methods of the class, at
the top of the file, write:
#define BT_LOG_TAG "MY/TAG"
#define BT_CLOG_CFG _mLogCfg
#include "cpp-common/cfg-logging-error-reporting-throw.hpp"
3. In any method of the class, when there's an error, call:
BT_CLOGE_APPEND_CAUSE_AND_THROW(bt2_common::Error,
"Cannot do this and that: code=%d",
code);
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3e689fe612b90be2f8f69288bc7947c727434d5a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10810
Tested-by: jenkins <jenkins@lttng.org>
This page took 0.045516 seconds and 4 git commands to generate.