X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Flib-logging.c;h=66bfe9d31a91f229c48de2a047e7013ddaf45ddf;hb=870631a2db01676b476dbee615aade0a22926bcd;hp=e29c2e901281b964c94c859b1ec8b8ccd7892a78;hpb=350ad6c1c5f45a4e90c33e3c1354125c209bbf02;p=babeltrace.git diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index e29c2e90..66bfe9d3 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -20,11 +20,8 @@ * SOFTWARE. */ -/* - * This is just to satisfy the preprocessor check in "lib/logging.h": - * this file does not log anything. - */ -#define BT_LOG_TAG "" +#define BT_LOG_TAG "LIB/LIB-LOGGING" +#include "lib/logging.h" #include #include @@ -35,13 +32,16 @@ #include #include #include "common/common.h" -#include "lib/value.h" -#include "lib/value.h" -#include "lib/object-pool.h" #include #include #include +#include +#include "logging.h" +#include "assert-pre.h" +#include "assert-post.h" +#include "value.h" +#include "object-pool.h" #include "graph/component-class.h" #include "graph/component-class-sink-colander.h" #include "graph/component-filter.h" @@ -59,7 +59,6 @@ #include "graph/message/stream-activity.h" #include "graph/message/stream.h" #include "graph/port.h" -#include "lib-logging.h" #include "plugin/plugin.h" #include "plugin/plugin-so.h" #include "trace-ir/clock-class.h" @@ -75,6 +74,7 @@ #include "trace-ir/trace-class.h" #include "trace-ir/trace.h" #include "trace-ir/utils.h" +#include "error.h" #include "assert-pre.h" #define LIB_LOGGING_BUF_SIZE (4096 * 4) @@ -1055,8 +1055,9 @@ static inline void format_component(char **buf_ch, bool extended, { char tmp_prefix[TMP_PREFIX_LEN]; - BUF_APPEND(", %sname=\"%s\"", - PRFIELD_GSTRING(component->name)); + BUF_APPEND(", %sname=\"%s\", %slog-level=%s", + PRFIELD_GSTRING(component->name), + PRFIELD(bt_common_logging_level_string(component->log_level))); if (component->class) { SET_TMP_PREFIX("class-"); @@ -1280,6 +1281,66 @@ static inline void format_plugin(char **buf_ch, bool extended, } } +static inline void format_error_cause(char **buf_ch, bool extended, + const char *prefix, const struct bt_error_cause *cause) +{ + const struct bt_error_cause_component_class_id *comp_class_id = NULL; + + BUF_APPEND(", %sactor-type=%s, %smodule-name=\"%s\"", + PRFIELD(bt_error_cause_actor_type_string(cause->actor_type)), + PRFIELD_GSTRING(cause->module_name)); + + if (!extended) { + return; + } + + BUF_APPEND(", %spartial-msg=\"%.32s\"", + PRFIELD_GSTRING(cause->message)); + + switch (cause->actor_type) { + case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT: + { + const struct bt_error_cause_component_actor *spec_cause = + (const void *) cause; + + BUF_APPEND(", %scomp-name=\"%s\"", + PRFIELD_GSTRING(spec_cause->comp_name)); + comp_class_id = &spec_cause->comp_class_id; + break; + } + case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS: + { + const struct bt_error_cause_component_class_actor *spec_cause = + (const void *) cause; + + comp_class_id = &spec_cause->comp_class_id; + break; + } + case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR: + { + const struct bt_error_cause_message_iterator_actor *spec_cause = + (const void *) cause; + + BUF_APPEND(", %scomp-name=\"%s\", %scomp-out-port-name=\"%s\"", + PRFIELD_GSTRING(spec_cause->comp_name), + PRFIELD_GSTRING(spec_cause->output_port_name)); + comp_class_id = &spec_cause->comp_class_id; + break; + } + default: + break; + } + + if (comp_class_id) { + BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", " + "%splugin-name=\"%s\"", + PRFIELD(bt_component_class_type_string( + comp_class_id->type)), + PRFIELD_GSTRING(comp_class_id->name), + PRFIELD_GSTRING(comp_class_id->plugin_name)); + } +} + static inline void handle_conversion_specifier_bt(void *priv_data, char **buf_ch, size_t avail_size, const char **out_fmt_ch, va_list *args) @@ -1401,6 +1462,9 @@ static inline void handle_conversion_specifier_bt(void *priv_data, case 'O': format_object(buf_ch, extended, prefix, obj); break; + case 'r': + format_error_cause(buf_ch, extended, prefix, obj); + break; default: abort(); } @@ -1422,3 +1486,41 @@ void bt_lib_log(const char *func, const char *file, unsigned line, va_end(args); _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf); } + +void bt_lib_maybe_log_and_append_cause(const char *func, const char *file, + unsigned line, int lvl, const char *tag, + const char *fmt, ...) +{ + va_list args; + bt_current_thread_error_append_cause_status status; + + BT_ASSERT(fmt); + va_start(args, fmt); + bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', + handle_conversion_specifier_bt, NULL, fmt, &args); + va_end(args); + + /* Log conditionally, but always append the error cause */ + if (BT_LOG_ON(lvl)) { + _bt_log_write_d(func, file, line, lvl, tag, "%s", + lib_logging_buf); + } + + status = bt_current_thread_error_append_cause_from_unknown( + "Babeltrace library", file, line, "%s", lib_logging_buf); + if (status) { + /* + * Worst case: this error cause is not appended to the + * current thread's error. + * + * We can accept this as it's an almost impossible + * scenario and returning an error here would mean you + * need to check the return value of each + * BT_LIB_LOG*_APPEND_CAUSE() macro and that would be + * cumbersome. + */ + BT_LOGE("Cannot append error cause to current thread's " + "error object: status=%s", + bt_common_func_status_string(status)); + } +}