Fix: bt2c::Logger: include the `errno` message into an error cause too
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 2 Feb 2024 20:19:24 +0000 (15:19 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 5 Feb 2024 18:11:59 +0000 (13:11 -0500)
commitd88930bcfe55bfaf69841da4905ade250353495c
treec502e14f08abc20d9743f312e57916ceede020a6
parent4d0dd57967e530711b2a818e41761ae34f456f99
Fix: bt2c::Logger: include the `errno` message into an error cause too

The observed issue is that, when using a BT_CPPLOG_ERRNO*APPEND*()
macro, the logger logs the `errno` message (for example,
`Invalid argument`), but the message of the appended error cause doesn't
contain it.

This is because `bt2c::Logger` relies on bt_log_write_errno() to include
the `errno` message (bt_log_write_errno() is the one calling
g_strerror()).

To fix this, don't call bt_log_write_errno() anymore: consider `initMsg`
in the general private methods (like _logStrNoThrow()), and format an
introductory message (`initMsg`, `: `, and then the result of
g_strerror()) directly into the logErrno*() methods. See the new static
_errnoIntroStr().

The `_InitMsgLogWriter` writer makes the concatenation of `initMsg`
and `msg` using bt_log_write_printf():

    bt_log_write_printf(funcName, fileName, lineNo,
                        static_cast<bt_log_level>(level), tag, "%s%s",
                        initMsg, msg);

`_StdLogWriter` ignores the `initMsg` parameter, but we only call it
when `initMsg` is an empty string anyway (I'm adding an assertion to
confirm that). For example, logStrNoThrow() calls _logStrNoThrow() with
`_StdLogWriter` and an empty `initMsg`. Same for `_MemLogWriter`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I50a0fda253b4cc2169dcdc91c84b80d251b3b82b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11740
src/cpp-common/bt2c/logging.hpp
This page took 0.02809 seconds and 4 git commands to generate.