Move to kernel style SPDX license identifiers
[babeltrace.git] / src / lib / logging.h
index 7bb36c99e2b94edf6288d23759171fd0732849e3..25699c84b81c5ae06aa44baf70b6cbb3a425a5ef 100644 (file)
@@ -1,28 +1,12 @@
-#ifndef BABELTRACE_LIB_LOGGING_INTERNAL_H
-#define BABELTRACE_LIB_LOGGING_INTERNAL_H
-
 /*
- * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
+ * SPDX-License-Identifier: MIT
  *
- * 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:
- *
- * 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 2017-2018 Philippe Proulx <pproulx@efficios.com>
  */
 
+#ifndef BABELTRACE_LIB_LOGGING_INTERNAL_H
+#define BABELTRACE_LIB_LOGGING_INTERNAL_H
+
 #include "common/macros.h"
 #include <stdarg.h>
 
@@ -34,6 +18,8 @@
 
 #include "logging/log.h"
 
+#define BT_LIB_LOG_LIBBABELTRACE2_NAME "libbabeltrace2"
+
 extern
 int bt_lib_log_level;
 
@@ -46,150 +32,66 @@ int bt_lib_log_level;
                }                                                       \
        } while (0)
 
-/*
- * The six macros below are logging statements which are specialized
- * for the Babeltrace library.
- *
- * `_fmt` is a typical printf()-style format string, with the following
- * limitations:
- *
- * * The `*` width specifier is not accepted.
- * * The `*` precision specifier is not accepted.
- * * The `j` and `t` length modifiers are not accepted.
- * * The `n` format specifier is not accepted.
- * * The format specifiers defined in <inttypes.h> are not accepted
- *   except for `PRId64`, `PRIu64`, `PRIx64`, `PRIX64`, `PRIo64`, and
- *   `PRIi64`.
- *
- * The Babeltrace extension conversion specifier is accepted. Its syntax
- * is either `%!u` to format a UUID (`bt_uuid` type) or:
- *
- * 1. Introductory `%!` sequence.
- *
- * 2. Optional: `[` followed by a custom prefix for the printed fields
- *    of this specifier, followed by `]`. The standard form is to end
- *    this prefix with `-` so that, for example, with the prefix
- *    `prefix-`, the complete field name is `prefix-addr`.
- *
- * 3. Optional: `+` to print extended fields. This depends on the
- *    provided format specifier.
- *
- * 4. Format specifier (see below).
- *
- * The available format specifiers are:
- *
- *   `F`:
- *       Trace IR field class. The parameter type is
- *      `struct bt_field_class *`.
- *
- *   `f`:
- *       Trace IR field. The parameter type is `struct bt_field *`.
- *
- *   `P`:
- *       Field path. The parameter type is `struct bt_field_path *`.
- *
- *   `E`:
- *       Trace IR event class. The parameter type is
- *      `struct bt_event_class *`.
- *
- *   `e`:
- *       Trace IR event. The parameter type is `struct bt_event *`.
- *
- *   `S`:
- *       Trace IR stream class. The parameter type is
- *      `struct bt_stream_class *`.
- *
- *   `s`:
- *       Trace IR stream. The parameter type is `struct bt_stream *`.
- *
- *   `a`:
- *       Packet. The parameter type is `struct bt_packet *`.
- *
- *   `T`:
- *       Trace IR trace class. The parameter type is `struct bt_trace_class *`.
- *
- *   `t`:
- *       Trace IR trace. The parameter type is `struct bt_trace *`.
- *
- *   `K`:
- *       Clock class. The parameter type is `struct bt_clock_class *`.
- *
- *   `k`:
- *       Clock snapshot. The parameter type is `struct bt_clock_snapshot *`.
- *
- *   `v`:
- *       Value. The parameter type is `struct bt_value *`.
- *
- *   `n`:
- *       Message. The parameter type is `struct bt_message *`.
- *
- *   `i`:
- *       Message iterator. The parameter type is
- *       `struct bt_message_iterator *`.
- *
- *   `C`:
- *       Component class. The parameter type is
- *      `struct bt_component_class *`.
- *
- *   `c`:
- *       Component. The parameter type is `struct bt_component *`.
- *
- *   `p`:
- *       Port. The parameter type is `struct bt_port *`.
- *
- *   `x`:
- *       Connection. The parameter type is `struct bt_connection *`.
- *
- *   `g`:
- *       Graph. The parameter type is `struct bt_graph *`.
- *
- *   `l`:
- *       Plugin. The parameter type is `const struct bt_plugin *`.
- *
- *   `o`:
- *       Object pool. The parameter type is `struct bt_object_pool *`.
- *
- *   `O`:
- *       Object. The parameter type is `struct bt_object *`.
- *
- * Conversion specifier examples:
- *
- *     %!f
- *     %![my-event-]+e
- *     %!t
- *     %!+F
- *
- * The string `, ` is printed between individual fields, but not after
- * the last one. Therefore you must put this separator in the format
- * string between two conversion specifiers, e.g.:
- *
- *     BT_LIB_LOGW("Message: count=%u, %!E, %!+K", count, event_class,
- *                 clock_class);
- *
- * Example with a custom prefix:
- *
- *     BT_LIB_LOGI("Some message: %![ec-a-]e, %![ec-b-]+e", ec_a, ec_b);
- *
- * It is safe to pass NULL as any Babeltrace object parameter: the
- * macros only print its null address.
- */
+/* See `CONTRIBUTING.adoc` for usage */
 #define BT_LIB_LOGF(_fmt, ...) BT_LIB_LOG(BT_LOG_FATAL, _fmt, ##__VA_ARGS__)
 #define BT_LIB_LOGE(_fmt, ...) BT_LIB_LOG(BT_LOG_ERROR, _fmt, ##__VA_ARGS__)
-#define BT_LIB_LOGW(_fmt, ...) BT_LIB_LOG(BT_LOG_WARN, _fmt, ##__VA_ARGS__)
+#define BT_LIB_LOGW(_fmt, ...) BT_LIB_LOG(BT_LOG_WARNING, _fmt, ##__VA_ARGS__)
 #define BT_LIB_LOGI(_fmt, ...) BT_LIB_LOG(BT_LOG_INFO, _fmt, ##__VA_ARGS__)
 #define BT_LIB_LOGD(_fmt, ...) BT_LIB_LOG(BT_LOG_DEBUG, _fmt, ##__VA_ARGS__)
-#define BT_LIB_LOGV(_fmt, ...) BT_LIB_LOG(BT_LOG_VERBOSE, _fmt, ##__VA_ARGS__)
+#define BT_LIB_LOGT(_fmt, ...) BT_LIB_LOG(BT_LOG_TRACE, _fmt, ##__VA_ARGS__)
 
 /*
  * Log statement, specialized for the Babeltrace library.
  *
- * Use one of the BT_LIB_LOGF*() macros above instead of calling this
+ * This function does NOT check that logging is enabled for level `lvl`:
+ * you must check it manually with BT_LOG_ON().
+ *
+ * Use one of the BT_LIB_LOG*() macros above instead of calling this
  * function directly.
+ *
+ * This function would normally be BT_HIDDEN, but it is used by the Python
+ * plugin provider, which is conceptually part of libbabeltrace2, but
+ * implemented as a separate shared object, for modularity.  It is therefore
+ * exposed, but not part of the public ABI.
  */
-
 void bt_lib_log(const char *func, const char *file, unsigned line,
                int lvl, const char *tag, const char *fmt, ...);
 
+#define BT_LIB_LOG_AND_APPEND(_lvl, _fmt, ...)                         \
+       do {                                                            \
+               bt_lib_maybe_log_and_append_cause(                      \
+                       _BT_LOG_SRCLOC_FUNCTION, __FILE__,              \
+                       __LINE__, _lvl, _BT_LOG_TAG,                    \
+                       (_fmt), ##__VA_ARGS__);                         \
+       } while (0)
+
+/* See `CONTRIBUTING.adoc` for usage */
+#define BT_LIB_LOGE_APPEND_CAUSE(_fmt, ...)                            \
+       BT_LIB_LOG_AND_APPEND(BT_LOG_ERROR, _fmt, ##__VA_ARGS__)
+#define BT_LIB_LOGW_APPEND_CAUSE(_fmt, ...)                            \
+       BT_LIB_LOG_AND_APPEND(BT_LOG_WARNING, _fmt, ##__VA_ARGS__)
+
+/*
+ * Like bt_lib_log(), but also appends a cause to the current thread's
+ * error object.
+ *
+ * Note that, unlike bt_lib_log(), this function does check that logging
+ * is enabled for level `lvl` before logging. This is to ensure that,
+ * even though logging is disabled, the function still appends an error
+ * cause, as the error reporting system does not rely on logging.
+ *
+ * Use one of the BT_LIB_LOG*_APPEND_CAUSE() macros above instead of
+ * calling this function directly.
+ *
+ * This function would normally be BT_HIDDEN, but it is used by the Python
+ * plugin provider, which is conceptually part of libbabeltrace2, but
+ * implemented as a separate shared object, for modularity.  It is therefore
+ * exposed, but not part of the ABI.
+ */
+void bt_lib_maybe_log_and_append_cause(const char *func, const char *file,
+               unsigned line, int lvl, const char *tag,
+               const char *fmt, ...);
+
 #define BT_LIB_LOG_SUPPORTED
 
 #endif /* BABELTRACE_LIB_LOGGING_INTERNAL_H */
This page took 0.025219 seconds and 4 git commands to generate.