lib: move trace class's name, UUID, and environment props to trace API
[babeltrace.git] / src / lib / lib-logging.c
index 1c5338c55ecb9ea953f195d0ccf4ed578b9d9f89..4c69d62f5b034cf778f0c0fb9bb91a6c6bb51310 100644 (file)
  * 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 <stdarg.h>
 #include <stdio.h>
@@ -38,6 +35,7 @@
 #include <babeltrace2/trace-ir/event-const.h>
 #include <babeltrace2/trace-ir/packet-const.h>
 #include <babeltrace2/trace-ir/stream-const.h>
+#include <babeltrace2/current-thread.h>
 
 #include "logging.h"
 #include "assert-pre.h"
@@ -453,21 +451,12 @@ static inline void format_field_path(char **buf_ch, bool extended,
 static inline void format_trace_class(char **buf_ch, bool extended,
                const char *prefix, const struct bt_trace_class *trace_class)
 {
-       if (trace_class->name.value) {
-               BUF_APPEND(", %sname=\"%s\"",
-                       PRFIELD(trace_class->name.value));
-       }
-
        if (!extended) {
                return;
        }
 
        BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class->frozen));
 
-       if (trace_class->uuid.value) {
-               BUF_APPEND_UUID(trace_class->uuid.value);
-       }
-
        if (trace_class->stream_classes) {
                BUF_APPEND(", %sstream-class-count=%u",
                        PRFIELD(trace_class->stream_classes->len));
@@ -490,6 +479,10 @@ static inline void format_trace(char **buf_ch, bool extended,
                return;
        }
 
+       if (trace->uuid.value) {
+               BUF_APPEND_UUID(trace->uuid.value);
+       }
+
        BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace->frozen));
 
        if (trace->streams) {
@@ -1488,3 +1481,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));
+       }
+}
This page took 0.024244 seconds and 4 git commands to generate.