Logging: add `src/plugins/comp-logging.h` (BT_COMP_LOG*())
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 15 Jun 2019 15:04:54 +0000 (11:04 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 20 Jun 2019 18:01:16 +0000 (14:01 -0400)
commitdd6aa1190869aa7c87e6f90f7ed9aa785371373a
tree217a5ccac39eeccd1767e7d9551862e3c3f643c9
parent0d9a3d3edc52d78d00ce114f6c4c50d6d334b9dd
Logging: add `src/plugins/comp-logging.h` (BT_COMP_LOG*())

This new header is intended to be included by the different component
class files so that their logging statements can automatically include
the component's name. The BT_COMP_LOG*() macros prepend a prefix similar
to this to the logging message:

    [mein-sink]

where `mein-sink` is a component's name.

Having the component name within each logging message of a given
component class adds valuable context and can help resolve issues
faster.

I did not include the plugin name and the component class's type and
name within the prefix because we already have them thanks to the
logging tag, for example `PLUGIN/SRC.CTF.FS`. This would be redundant,
make the logging message longer, and make `comp-logging.h` more complex.

The BT_COMP_LOG*() macros rely on the `BT_COMP_LOG_SELF_COMP`
definition. This is an expression which is, in the logging statement
context, the `bt_self_component *` address. Because we have the self
component there, we are free to prepend more contextual information to
the logging message in the future, should we need it.

Typically, when a component class source file defines
`BT_LOG_OUTPUT_LEVEL` to `(my_comp->log_level)`, where `my_comp` points
to the component's private structure, it will also define
`BT_COMP_LOG_SELF_COMP` to `(my_comp->self_comp)`.

If `BT_COMP_LOG_SELF_COMP` evaluates to `NULL`, the macros use the
prefix

    [N/A]

This could be the case when instrumenting code that is shared for both
graph and non-graph contexts, for example the metadata and stream
decoders of the `ctf` plugin which can also be used within a query
operation.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I62c63ed78d234922f556631726fb7bb852924f0a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1468
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/plugins/Makefile.am
src/plugins/comp-logging.h [new file with mode: 0644]
This page took 0.024843 seconds and 4 git commands to generate.