Move bt_message_type_string to common
[babeltrace.git] / src / lib / lib-logging.c
index 2a10c68dc05306aaaa42c696860e74e5e63b6fa0..df73244b22e969978054b679d7330c97357d1f6e 100644 (file)
@@ -1,23 +1,7 @@
 /*
- * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
+ * SPDX-License-Identifier: MIT
  *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
  */
 
 #define BT_LOG_TAG "LIB/LIB-LOGGING"
@@ -37,8 +21,7 @@
 #include <babeltrace2/babeltrace.h>
 
 #include "logging.h"
-#include "assert-pre.h"
-#include "assert-post.h"
+#include "assert-cond.h"
 #include "value.h"
 #include "integer-range-set.h"
 #include "object-pool.h"
@@ -74,7 +57,6 @@
 #include "trace-ir/trace.h"
 #include "trace-ir/utils.h"
 #include "error.h"
-#include "assert-pre.h"
 
 #define LIB_LOGGING_BUF_SIZE   (4096 * 4)
 
@@ -347,6 +329,8 @@ static inline void format_field_integer_extended(char **buf_ch,
                fmt = ", %svalue=%" PRIx64;
        }
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
        if (field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER ||
                        field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) {
                if (!fmt) {
@@ -361,6 +345,7 @@ static inline void format_field_integer_extended(char **buf_ch,
 
                BUF_APPEND(fmt, PRFIELD(integer->value.u));
        }
+#pragma GCC diagnostic pop
 }
 
 static inline void format_field(char **buf_ch, bool extended,
@@ -947,7 +932,7 @@ static inline void format_message(char **buf_ch, bool extended,
        char tmp_prefix[TMP_PREFIX_LEN];
 
        BUF_APPEND(", %stype=%s",
-               PRFIELD(bt_message_type_string(msg->type)));
+               PRFIELD(bt_common_message_type_string(msg->type)));
 
        if (!extended) {
                return;
@@ -1072,7 +1057,7 @@ static inline void format_component_class(char **buf_ch, bool extended,
        char tmp_prefix[TMP_PREFIX_LEN];
 
        BUF_APPEND(", %stype=%s, %sname=\"%s\"",
-               PRFIELD(bt_component_class_type_string(comp_class->type)),
+               PRFIELD(bt_common_component_class_type_string(comp_class->type)),
                PRFIELD_GSTRING(comp_class->name));
 
        if (comp_class->description) {
@@ -1350,7 +1335,7 @@ static inline void format_error_cause(char **buf_ch, bool extended,
        if (comp_class_id) {
                BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", "
                        "%splugin-name=\"%s\"",
-                       PRFIELD(bt_component_class_type_string(
+                       PRFIELD(bt_common_component_class_type_string(
                                comp_class_id->type)),
                        PRFIELD_GSTRING(comp_class_id->name),
                        PRFIELD_GSTRING(comp_class_id->plugin_name));
@@ -1499,6 +1484,15 @@ update_fmt:
        *out_fmt_ch = fmt_ch;
 }
 
+void bt_lib_log_v(const char *func, const char *file, unsigned line,
+               int lvl, const char *tag, const char *fmt, va_list *args)
+{
+       BT_ASSERT(fmt);
+       bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!',
+               handle_conversion_specifier_bt, NULL, fmt, args);
+       _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf);
+}
+
 void bt_lib_log(const char *func, const char *file, unsigned line,
                int lvl, const char *tag, const char *fmt, ...)
 {
@@ -1506,10 +1500,8 @@ void bt_lib_log(const char *func, const char *file, unsigned line,
 
        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);
+       bt_lib_log_v(func, file, line, lvl, tag, fmt, &args);
        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,
This page took 0.024952 seconds and 4 git commands to generate.