Remove legacy printf_verbose()/printf_debug() and others
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 14 Jun 2017 20:30:31 +0000 (16:30 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 14 Jun 2017 22:05:54 +0000 (18:05 -0400)
This patch removes all the legacy logging macros found in
babeltrace-internal.h. It also removes the babeltrace_verbose and
babeltrace_debug symbols.

To remain as backward compatible as possible, the CLI checks the
BABELTRACE_VERBOSE and BABELTRACE_DEBUG environment variables and
overrides the default log level (WARN, or the one set with --log-level)
with VERBOSE if BABELTRACE_DEBUG is 1 and INFO if only
BABELTRACE_VERBOSE is 1. This default log level applies to all the known
loggers, except the ones that have their log level explicitly set with a
dedicated environment variable.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 files changed:
cli/babeltrace-cfg-cli-args.c
cli/babeltrace.c
common/Makefile.am
common/common.c
common/logging.c [new file with mode: 0644]
common/logging.h [new file with mode: 0644]
include/babeltrace/babeltrace-internal.h
lib/babeltrace.c
plugins/lttng-utils/Makefile.am
plugins/lttng-utils/bin-info.c
plugins/lttng-utils/debug-info.c
plugins/lttng-utils/logging.c [new file with mode: 0644]
plugins/lttng-utils/logging.h [new file with mode: 0644]
plugins/lttng-utils/plugin.c
plugins/text/Makefile.am
plugins/utils/trimmer/Makefile.am
plugins/utils/trimmer/iterator.c
plugins/utils/trimmer/logging.c [new file with mode: 0644]
plugins/utils/trimmer/logging.h [new file with mode: 0644]
plugins/utils/trimmer/trimmer.c

index 541329ab136bc53bfc53bb1cdf221ca9419cd2d8..65334db67da4b501ce348fa60701722c50813427 100644 (file)
@@ -22,6 +22,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "CLI-CFG-CLI-ARGS"
+#include "logging.h"
+
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
@@ -39,9 +42,6 @@
 #include "babeltrace-cfg-cli-args.h"
 #include "babeltrace-cfg-cli-args-connect.h"
 
-#define BT_LOG_TAG "CLI-CFG-ARGS"
-#include "logging.h"
-
 /*
  * Error printf() macro which prepends "Error: " the first time it's
  * called. This gives a nicer feel than having a bunch of error prefixes
@@ -1410,7 +1410,7 @@ int append_env_var_plugin_paths(struct bt_value *plugin_paths)
        const char *envvar;
 
        if (bt_common_is_setuid_setgid()) {
-               printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
+               BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
                goto end;
        }
 
@@ -1437,7 +1437,7 @@ int append_home_and_system_plugin_paths(struct bt_value *plugin_paths,
 
        if (!omit_home_plugin_path) {
                if (bt_common_is_setuid_setgid()) {
-                       printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
+                       BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
                } else {
                        char *home_plugin_dir =
                                bt_common_get_home_plugin_path();
@@ -1703,7 +1703,7 @@ int bt_config_append_plugin_paths_check_setuid_setgid(
        int ret = 0;
 
        if (bt_common_is_setuid_setgid()) {
-               printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
+               BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
                goto end;
        }
 
index 668491e7bdaecbb02afbd50a55f2cc6f32b3eee7..3c44db359025eb3e73936eb2b129ceac64d81b76 100644 (file)
  * modules.
  */
 static const char* log_level_env_var_names[] = {
+       "BABELTRACE_COMMON_LOG_LEVEL",
        "BABELTRACE_PLUGIN_CTF_BTR_LOG_LEVEL",
        "BABELTRACE_PLUGIN_CTF_FS_SRC_LOG_LEVEL",
        "BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_SRC_LOG_LEVEL",
        "BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL",
        "BABELTRACE_PLUGIN_CTF_NOTIF_ITER_LOG_LEVEL",
+       "BABELTRACE_PLUGIN_LTTNG_UTILS_DEBUG_INFO_FLT_LOG_LEVEL",
+       "BABELTRACE_PLUGIN_UTILS_TRIMMER_FLT_LOG_LEVEL",
        "BABELTRACE_PYTHON_PLUGIN_PROVIDER_LOG_LEVEL",
        NULL,
 };
@@ -1918,6 +1921,19 @@ void set_auto_log_levels(struct bt_config *cfg)
 {
        const char **env_var_name;
 
+       /*
+        * Override the configuration's default log level if
+        * BABELTRACE_VERBOSE or BABELTRACE_DEBUG environment variables
+        * are found for backward compatibility with legacy Babetrace 1.
+        */
+       if (getenv("BABELTRACE_DEBUG") &&
+                       strcmp(getenv("BABELTRACE_DEBUG"), "1") == 0) {
+               cfg->log_level = 'V';
+       } else if (getenv("BABELTRACE_VERBOSE") &&
+                       strcmp(getenv("BABELTRACE_VERBOSE"), "1") == 0) {
+               cfg->log_level = 'I';
+       }
+
        /*
         * Set log levels according to --debug or --verbose. For
         * backward compatibility, --debug is more verbose than
@@ -2026,9 +2042,6 @@ void set_auto_log_levels(struct bt_config *cfg)
 
                env_var_name++;
        }
-
-       babeltrace_debug = cfg->debug;
-       babeltrace_verbose = cfg->verbose;
 }
 
 static
index a4543ddccf7e6751d024e93a085dbb7cf676bc03..4c902fa482f12cb354f0260e799c33a4f807a7a9 100644 (file)
@@ -4,4 +4,4 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include \
 
 noinst_LTLIBRARIES = libbabeltrace-common.la
 
-libbabeltrace_common_la_SOURCES = common.c
+libbabeltrace_common_la_SOURCES = common.c logging.c logging.h
index 96532e2bd8bfe0c3a33ca556b2cef3006be1528e..0a0d15836e329d866c40286ded145f209d671b2e 100644 (file)
@@ -22,6 +22,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "COMMON"
+#include "logging.h"
+
 #include <unistd.h>
 #include <string.h>
 #include <sys/types.h>
@@ -110,8 +113,8 @@ static
 char *bt_secure_getenv(const char *name)
 {
        if (bt_common_is_setuid_setgid()) {
-               printf_error("Disregarding %s environment variable for setuid/setgid binary",
-                       name);
+               BT_LOGD("Disregarding environment variable for setuid/setgid binary: "
+                       "name=\"%s\"", name);
                return NULL;
        }
        return getenv(name);
@@ -150,15 +153,18 @@ char *bt_common_get_home_plugin_path(void)
 {
        char *path = NULL;
        const char *home_dir;
+       size_t length;
 
        home_dir = bt_get_home_dir();
        if (!home_dir) {
                goto end;
        }
 
-       if (strlen(home_dir) + strlen(HOME_PLUGIN_SUBPATH) + 1 >= PATH_MAX) {
-               printf_error("Home directory path is too long: `%s`\n",
-                       home_dir);
+       length = strlen(home_dir) + strlen(HOME_PLUGIN_SUBPATH) + 1;
+
+       if (length >= PATH_MAX) {
+               BT_LOGW("Home directory path is too long: length=%zu",
+                       length);
                goto end;
        }
 
@@ -1163,7 +1169,8 @@ size_t bt_common_get_page_size(void)
 
        page_size = bt_sysconf(_SC_PAGESIZE);
        if (page_size < 0) {
-               printf_error("Cannot get system page size.");
+               BT_LOGF("Cannot get system's page size: ret=%d",
+                       page_size);
                abort();
        }
 
diff --git a/common/logging.c b/common/logging.c
new file mode 100644 (file)
index 0000000..6e520d2
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2017 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:
+ *
+ * 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.
+ */
+
+#define BT_LOG_OUTPUT_LEVEL bt_common_log_level
+#include <babeltrace/logging-internal.h>
+
+BT_LOG_INIT_LOG_LEVEL(bt_common_log_level, "BABELTRACE_COMMON_LOG_LEVEL");
diff --git a/common/logging.h b/common/logging.h
new file mode 100644 (file)
index 0000000..c5b8e5e
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef COMMON_LOGGING_H
+#define COMMON_LOGGING_H
+
+/*
+ * Copyright (c) 2017 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:
+ *
+ * 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.
+ */
+
+#define BT_LOG_OUTPUT_LEVEL bt_common_log_level
+#include <babeltrace/logging-internal.h>
+
+BT_LOG_LEVEL_EXTERN_SYMBOL(bt_common_log_level);
+
+#endif /* COMMON_LOGGING_H */
index 006bf8f3c7954618eb10fc9772ed6ce4822a6775..1bdd79ece3ee19e6ca5b6005f9cf9ed21b6adf09 100644 (file)
 
 #define PERROR_BUFLEN  200
 
-extern bt_bool babeltrace_verbose, babeltrace_debug;
-
-#define printf_verbose(fmt, args...)                                   \
-       do {                                                            \
-               if (babeltrace_verbose)                                 \
-                       fprintf(stdout, "[verbose] " fmt, ## args);     \
-       } while (0)
-
-#define printf_debug(fmt, args...)                                     \
-       do {                                                            \
-               if (babeltrace_debug)                                   \
-                       fprintf(stdout, "[debug] " fmt, ## args);       \
-       } while (0)
-
-#define _bt_printf(fp, kindstr, fmt, args...)                          \
-       fprintf(fp, "[%s]%s%s%s: " fmt "\n",                            \
-               kindstr,                                                \
-               babeltrace_debug ? " \"" : "",                          \
-               babeltrace_debug ? __func__ : "",                       \
-               babeltrace_debug ? "\"" : "",                           \
-               ## args)
-
-#define _bt_printfl(fp, kindstr, lineno, fmt, args...)                 \
-       fprintf(fp, "[%s]%s%s%s at line %u: " fmt "\n",                 \
-               kindstr,                                                \
-               babeltrace_debug ? " \"" : "",                          \
-               babeltrace_debug ? __func__ : "",                       \
-               babeltrace_debug ? "\"" : "",                           \
-               lineno,                                                 \
-               ## args)
-
-#define _bt_printfe(fp, kindstr, perrorstr, fmt, args...)              \
-       fprintf(fp, "[%s]%s%s%s: %s: " fmt "\n",                        \
-               kindstr,                                                \
-               babeltrace_debug ? " \"" : "",                          \
-               babeltrace_debug ? __func__ : "",                       \
-               babeltrace_debug ? "\"" : "",                           \
-               perrorstr,                                              \
-               ## args)
-
-#define _bt_printfle(fp, kindstr, lineno, perrorstr, fmt, args...)     \
-       fprintf(fp, "[%s]%s%s%s at line %u: %s: " fmt "\n",             \
-               kindstr,                                                \
-               babeltrace_debug ? " \"" : "",                          \
-               babeltrace_debug ? __func__ : "",                       \
-               babeltrace_debug ? "\"" : "",                           \
-               lineno,                                                 \
-               perrorstr,                                              \
-               ## args)
-
-#define _bt_printf_perror(fp, fmt, args...)                            \
-       ({                                                              \
-               const char *errstr;                                     \
-               errstr = g_strerror(errno);                             \
-               _bt_printfe(fp, "error", errstr, fmt, ## args);         \
-       })
-
-#define _bt_printfl_perror(fp, lineno, fmt, args...)                   \
-       ({                                                              \
-               const char *errstr;                                     \
-               errstr = g_strerror(errno);                             \
-               _bt_printfle(fp, "error", lineno, errstr, fmt, ## args);\
-       })
-
-/* printf without lineno information */
-#define printf_fatal(fmt, args...)                                     \
-       _bt_printf(stderr, "fatal", fmt, ## args)
-#define printf_error(fmt, args...)                                     \
-       _bt_printf(stderr, "error", fmt, ## args)
-#define printf_warning(fmt, args...)                                   \
-       _bt_printf(stderr, "warning", fmt, ## args)
-#define printf_perror(fmt, args...)                                    \
-       _bt_printf_perror(stderr, fmt, ## args)
-
-/* printf with lineno information */
-#define printfl_fatal(lineno, fmt, args...)                            \
-       _bt_printfl(stderr, "fatal", lineno, fmt, ## args)
-#define printfl_error(lineno, fmt, args...)                            \
-       _bt_printfl(stderr, "error", lineno, fmt, ## args)
-#define printfl_warning(lineno, fmt, args...)                          \
-       _bt_printfl(stderr, "warning", lineno, fmt, ## args)
-#define printfl_perror(lineno, fmt, args...)                           \
-       _bt_printfl_perror(stderr, lineno, fmt, ## args)
-
-/* printf with node lineno information */
-#define printfn_fatal(node, fmt, args...)                              \
-       _bt_printfl(stderr, "fatal", (node)->lineno, fmt, ## args)
-#define printfn_error(node, fmt, args...)                              \
-       _bt_printfl(stderr, "error", (node)->lineno, fmt, ## args)
-#define printfn_warning(node, fmt, args...)                            \
-       _bt_printfl(stderr, "warning", (node)->lineno, fmt, ## args)
-#define printfn_perror(node, fmt, args...)                             \
-       _bt_printfl_perror(stderr, (node)->lineno, fmt, ## args)
-
-/* fprintf with Node lineno information */
-#define fprintfn_fatal(fp, node, fmt, args...)                         \
-       _bt_printfl(fp, "fatal", (node)->lineno, fmt, ## args)
-#define fprintfn_error(fp, node, fmt, args...)                         \
-       _bt_printfl(fp, "error", (node)->lineno, fmt, ## args)
-#define fprintfn_warning(fp, node, fmt, args...)                       \
-       _bt_printfl(fp, "warning", (node)->lineno, fmt, ## args)
-#define fprintfn_perror(fp, node, fmt, args...)                                \
-       _bt_printfl_perror(fp, (node)->lineno, fmt, ## args)
-
 #ifndef likely
 # ifdef __GNUC__
 #  define likely(x)      __builtin_expect(!!(x), 1)
index 2b675eb299d4eb18a7efd5b6853ae70fe97aa43e..ab2b6bc8d2c82af3eb7d6623813c4c1fcc34aacf 100644 (file)
 #include <babeltrace/types.h>
 #include <stdlib.h>
 
-bt_bool babeltrace_verbose, babeltrace_debug;
-
-static
-void __attribute__((constructor)) init_babeltrace_lib(void)
-{
-       if (getenv("BABELTRACE_VERBOSE"))
-               babeltrace_verbose = BT_TRUE;
-       if (getenv("BABELTRACE_DEBUG"))
-               babeltrace_debug = BT_TRUE;
-}
-
 int bt_version_get_major(void)
 {
        return BT_VERSION_MAJOR;
index 8f0975d61fb26513eca15576c72464e217167e96..7d731996f09de811e4b517cd940d5f7d2cc15db4 100644 (file)
@@ -12,7 +12,9 @@ noinst_HEADERS = \
        dwarf.h \
        bin-info.h \
        utils.h \
-       copy.h
+       copy.h \
+       logging.c \
+       logging.h
 
 libbabeltrace_plugin_lttng_utils_la_SOURCES = \
        plugin.c debug-info.h debug-info.c bin-info.c dwarf.c crc32.c utils.c \
@@ -26,5 +28,7 @@ libbabeltrace_plugin_lttng_utils_la_LDFLAGS = \
 if !BUILT_IN_PLUGINS
 libbabeltrace_plugin_lttng_utils_la_LIBADD = \
        $(top_builddir)/lib/libbabeltrace.la \
+       $(top_builddir)/common/libbabeltrace-common.la \
+       $(top_builddir)/logging/libbabeltrace-logging.la \
        $(top_builddir)/plugins/libctfcopytrace/libctfcopytrace.la
 endif
index 170b351f20fdc4cc4e75b9c151bf94925b9ae6fe..689d5ad475ee03151845472ee185062d9479ea65 100644 (file)
@@ -26,6 +26,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "PLUGIN-CTF-LTTNG-UTILS-DEBUG-INFO-FLT-BIN-INFO"
+#include "logging.h"
+
 #include <fcntl.h>
 #include <math.h>
 #include <libgen.h>
@@ -37,7 +40,6 @@
 #include <dwarf.h>
 #include <glib.h>
 #include <errno.h>
-#include <babeltrace/babeltrace-internal.h>
 #include "dwarf.h"
 #include "bin-info.h"
 #include "crc32.h"
@@ -56,8 +58,8 @@ int bin_info_init(void)
        int ret = 0;
 
        if (elf_version(EV_CURRENT) == EV_NONE) {
-               printf_debug("ELF library initialization failed: %s\n",
-                               elf_errmsg(-1));
+               BT_LOGD("ELF library initialization failed: %s.",
+                       elf_errmsg(-1));
                ret = -1;
        }
 
@@ -507,19 +509,19 @@ int bin_info_set_elf_file(struct bin_info *bin)
        elf_fd = open(bin->elf_path, O_RDONLY);
        if (elf_fd < 0) {
                elf_fd = -errno;
-               printf_verbose("Failed to open %s\n", bin->elf_path);
+               BT_LOGD("Failed to open ELF file: path=\"%s\"", bin->elf_path);
                goto error;
        }
 
        elf_file = elf_begin(elf_fd, ELF_C_READ, NULL);
        if (!elf_file) {
-               printf_debug("elf_begin failed: %s\n", elf_errmsg(-1));
+               BT_LOGD("elf_begin() failed: %s.", elf_errmsg(-1));
                goto error;
        }
 
        if (elf_kind(elf_file) != ELF_K_ELF) {
-               printf_verbose("Error: %s is not an ELF object\n",
-                               bin->elf_path);
+               BT_LOGD("ELF file is not an ELF object: path=\"%s\"",
+                       bin->elf_path);
                goto error;
        }
 
@@ -932,7 +934,7 @@ int bin_info_lookup_function_name(struct bin_info *bin,
        if (!bin->dwarf_info && !bin->is_elf_only) {
                ret = bin_info_set_dwarf_info(bin);
                if (ret) {
-                       printf_verbose("Failed to set bin dwarf info, falling back to ELF lookup.\n");
+                       BT_LOGD_STR("Failed to set bin dwarf info, falling back to ELF lookup.");
                        /* Failed to set DWARF info, fallback to ELF. */
                        bin->is_elf_only = true;
                }
@@ -952,10 +954,10 @@ int bin_info_lookup_function_name(struct bin_info *bin,
 
        if (bin->is_elf_only) {
                ret = bin_info_lookup_elf_function_name(bin, addr, &_func_name);
-               printf_verbose("Failed to lookup function name (elf), error %i\n", ret);
+               BT_LOGD("Failed to lookup function name (ELF): ret=%d", ret);
        } else {
                ret = bin_info_lookup_dwarf_function_name(bin, addr, &_func_name);
-               printf_verbose("Failed to lookup function name (dwarf), error %i\n", ret);
+               BT_LOGD("Failed to lookup function name (DWARF): ret=%d", ret);
        }
 
        *func_name = _func_name;
index 2ac4002f910e998997efea8f2ef41fa71a2a3385..493898fdb43ef023c14cd2de603a3e8789f9bb85 100644 (file)
@@ -25,6 +25,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "PLUGIN-CTF-LTTNG-UTILS-DEBUG-INFO-FLT"
+#include "logging.h"
+
 #include <assert.h>
 #include <glib.h>
 #include "debug-info.h"
@@ -119,7 +122,7 @@ struct debug_info_source *debug_info_source_create_from_bin(struct bin_info *bin
        if (!bin->is_elf_only || !debug_info_src->func) {
                /* Lookup source location */
                ret = bin_info_lookup_source_location(bin, ip, &src_loc);
-               printf_verbose("Failed to lookup source location (err: %i)\n", ret);
+               BT_LOGD("Failed to lookup source location: ret=%d", ret);
        }
 
        if (src_loc) {
diff --git a/plugins/lttng-utils/logging.c b/plugins/lttng-utils/logging.c
new file mode 100644 (file)
index 0000000..3b57447
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 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:
+ *
+ * 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.
+ */
+
+#define BT_LOG_OUTPUT_LEVEL bt_plugin_lttng_utils_debug_info_log_level
+#include <babeltrace/logging-internal.h>
+
+BT_LOG_INIT_LOG_LEVEL(bt_plugin_lttng_utils_debug_info_log_level,
+       "BABELTRACE_PLUGIN_LTTNG_UTILS_DEBUG_INFO_FLT_LOG_LEVEL");
diff --git a/plugins/lttng-utils/logging.h b/plugins/lttng-utils/logging.h
new file mode 100644 (file)
index 0000000..b77a02f
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef PLUGINS_LTTNG_UTILS_DEBUG_INFO_LOGGING_H
+#define PLUGINS_LTTNG_UTILS_DEBUG_INFO_LOGGING_H
+
+/*
+ * Copyright (c) 2017 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:
+ *
+ * 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.
+ */
+
+#define BT_LOG_OUTPUT_LEVEL bt_plugin_lttng_utils_debug_info_log_level
+#include <babeltrace/logging-internal.h>
+
+BT_LOG_LEVEL_EXTERN_SYMBOL(bt_plugin_lttng_utils_debug_info_log_level);
+
+#endif /* PLUGINS_LTTNG_UTILS_DEBUG_INFO_LOGGING_H */
index 9436ee34f7a2edd2fb2572b0a889cb726961c19b..1b63b8db585d3f6df9529401b6e6b15540d04f5a 100644 (file)
@@ -26,6 +26,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "PLUGIN-CTF-LTTNG-UTILS-DEBUG-INFO-FLT"
+#include "logging.h"
+
 #include <babeltrace/graph/notification-iterator.h>
 #include <babeltrace/graph/private-notification-iterator.h>
 #include <babeltrace/graph/connection.h>
@@ -362,7 +365,7 @@ enum bt_component_status init_from_params(
                value_ret = bt_value_string_get(value, &tmp);
                if (value_ret) {
                        ret = BT_COMPONENT_STATUS_INVALID;
-                       printf_error("Failed to retrieve debug-info-field-name value. "
+                       BT_LOGE_STR("Failed to retrieve debug-info-field-name value. "
                                        "Expecting a string");
                }
                strcpy(debug_info_component->arg_debug_info_field_name, tmp);
@@ -372,7 +375,7 @@ enum bt_component_status init_from_params(
                        malloc(strlen("debug_info") + 1);
                if (!debug_info_component->arg_debug_info_field_name) {
                        ret = BT_COMPONENT_STATUS_NOMEM;
-                       printf_error();
+                       BT_LOGE_STR("Missing field name.");
                }
                sprintf(debug_info_component->arg_debug_info_field_name,
                                "debug_info");
@@ -389,7 +392,7 @@ enum bt_component_status init_from_params(
                                &debug_info_component->arg_debug_dir);
                if (value_ret) {
                        ret = BT_COMPONENT_STATUS_INVALID;
-                       printf_error("Failed to retrieve debug-dir value. "
+                       BT_LOGE_STR("Failed to retrieve debug-dir value. "
                                        "Expecting a string");
                }
        }
@@ -406,7 +409,7 @@ enum bt_component_status init_from_params(
                                &debug_info_component->arg_target_prefix);
                if (value_ret) {
                        ret = BT_COMPONENT_STATUS_INVALID;
-                       printf_error("Failed to retrieve target-prefix value. "
+                       BT_LOGE_STR("Failed to retrieve target-prefix value. "
                                        "Expecting a string");
                }
        }
@@ -424,7 +427,7 @@ enum bt_component_status init_from_params(
                                &bool_val);
                if (value_ret) {
                        ret = BT_COMPONENT_STATUS_INVALID;
-                       printf_error("Failed to retrieve full-path value. "
+                       BT_LOGE_STR("Failed to retrieve full-path value. "
                                        "Expecting a boolean");
                }
 
index 99364c5aaab03ed88a296fca40204067d124902e..03de922d038a936294eddc8c3657b75a92afdc0b 100644 (file)
@@ -15,5 +15,6 @@ libbabeltrace_plugin_text_la_LIBADD = \
 if !BUILT_IN_PLUGINS
 libbabeltrace_plugin_text_la_LIBADD += \
        $(top_builddir)/lib/libbabeltrace.la \
-       $(top_builddir)/common/libbabeltrace-common.la
+       $(top_builddir)/common/libbabeltrace-common.la \
+       $(top_builddir)/logging/libbabeltrace-logging.la
 endif
index 74bad1c912ebd36fc0cca7a6d45e7083a957ec06..db1ca0f93b325d432c56e72c2b8ba7c207f02d07 100644 (file)
@@ -8,11 +8,15 @@ libbabeltrace_plugin_trimmer_la_SOURCES = \
        copy.c \
        trimmer.h \
        iterator.h \
-       copy.h
+       copy.h \
+       logging.c \
+       logging.h
 
 libbabeltrace_plugin_trimmer_la_LIBADD =
 
 if !BUILT_IN_PLUGINS
 libbabeltrace_plugin_trimmer_la_LIBADD += \
-       $(top_builddir)/plugins/libctfcopytrace/libctfcopytrace.la
+       $(top_builddir)/plugins/libctfcopytrace/libctfcopytrace.la \
+       $(top_builddir)/common/libbabeltrace-common.la \
+       $(top_builddir)/logging/libbabeltrace-logging.la
 endif
index 1e94b15ecc6d5a1a0e588f5fc8860f2522bf9174..73b95ba7c6e0b715b36ca5002acb315622798abd 100644 (file)
@@ -26,6 +26,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "PLUGIN-UTILS-TRIMMER-FLT"
+#include "logging.h"
+
 #include <babeltrace/compat/time-internal.h>
 #include <babeltrace/compat/utc-internal.h>
 #include <babeltrace/graph/notification-iterator.h>
@@ -154,7 +157,7 @@ int update_lazy_bound(struct trimmer_bound *bound, const char *name,
        if (bound->lazy_values.gmt) {
                /* Get day, month, year. */
                if (!bt_gmtime_r(&timeval, &tm)) {
-                       printf_error("Failure in bt_gmtime_r()");
+                       BT_LOGE_STR("Failure in bt_gmtime_r()");
                        goto error;
                }
                tm.tm_sec = bound->lazy_values.ss;
@@ -162,14 +165,14 @@ int update_lazy_bound(struct trimmer_bound *bound, const char *name,
                tm.tm_hour = bound->lazy_values.hh;
                timeval = bt_timegm(&tm);
                if (timeval < 0) {
-                       printf_error("Failure in bt_timegm(), incorrectly formatted %s timestamp",
+                       BT_LOGE("Failure in bt_timegm(), incorrectly formatted %s timestamp",
                                        name);
                        goto error;
                }
        } else {
                /* Get day, month, year. */
                if (!bt_localtime_r(&timeval, &tm)) {
-                       printf_error("Failure in bt_localtime_r()");
+                       BT_LOGE_STR("Failure in bt_localtime_r()");
                        goto error;
                }
                tm.tm_sec = bound->lazy_values.ss;
@@ -177,7 +180,7 @@ int update_lazy_bound(struct trimmer_bound *bound, const char *name,
                tm.tm_hour = bound->lazy_values.hh;
                timeval = mktime(&tm);
                if (timeval < 0) {
-                       printf_error("Failure in mktime(), incorrectly formatted %s timestamp",
+                       BT_LOGE("Failure in mktime(), incorrectly formatted %s timestamp",
                                name);
                        goto error;
                }
@@ -243,14 +246,14 @@ struct bt_notification *evaluate_event_notification(
 
        clock_value = bt_ctf_event_get_clock_value(event, clock_class);
        if (!clock_value) {
-               printf_error("Failed to retrieve clock value");
+               BT_LOGE_STR("Failed to retrieve clock value");
                goto error;
        }
 
        clock_ret = bt_ctf_clock_value_get_value_ns_from_epoch(
                        clock_value, &ts);
        if (clock_ret) {
-               printf_error("Failed to retrieve clock value timestamp");
+               BT_LOGE_STR("Failed to retrieve clock value timestamp");
                goto error;
        }
        if (update_lazy_bound(begin, "begin", ts, &lazy_update)) {
@@ -261,7 +264,7 @@ struct bt_notification *evaluate_event_notification(
        }
        if (lazy_update && begin->set && end->set) {
                if (begin->value > end->value) {
-                       printf_error("Unexpected: time range begin value is above end value");
+                       BT_LOGE_STR("Unexpected: time range begin value is above end value");
                        goto error;
                }
        }
@@ -465,7 +468,7 @@ struct bt_notification *evaluate_packet_notification(
        }
        if (lazy_update && begin->set && end->set) {
                if (begin->value > end->value) {
-                       printf_error("Unexpected: time range begin value is above end value");
+                       BT_LOGE_STR("Unexpected: time range begin value is above end value");
                        goto end_no_notif;
                }
        }
diff --git a/plugins/utils/trimmer/logging.c b/plugins/utils/trimmer/logging.c
new file mode 100644 (file)
index 0000000..fffefda
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 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:
+ *
+ * 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.
+ */
+
+#define BT_LOG_OUTPUT_LEVEL bt_plugin_utils_trimmer_log_level
+#include <babeltrace/logging-internal.h>
+
+BT_LOG_INIT_LOG_LEVEL(bt_plugin_utils_trimmer_log_level,
+       "BABELTRACE_PLUGIN_UTILS_TRIMMER_FLT_LOG_LEVEL");
diff --git a/plugins/utils/trimmer/logging.h b/plugins/utils/trimmer/logging.h
new file mode 100644 (file)
index 0000000..d5ef128
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef PLUGINS_UTILS_TRIMMER_LOGGING_H
+#define PLUGINS_UTILS_TRIMMER_LOGGING_H
+
+/*
+ * Copyright (c) 2017 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:
+ *
+ * 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.
+ */
+
+#define BT_LOG_OUTPUT_LEVEL bt_plugin_utils_trimmer_log_level
+#include <babeltrace/logging-internal.h>
+
+BT_LOG_LEVEL_EXTERN_SYMBOL(bt_plugin_utils_trimmer_log_level);
+
+#endif /* PLUGINS_UTILS_TRIMMER_LOGGING_H */
index 2a8bd5e0b83c5fb4ae8d21977134a4cd432c536e..d3460fbb83e299380557e88530d5ea7e6b32f2bc 100644 (file)
@@ -26,6 +26,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "PLUGIN-UTILS-TRIMMER-FLT"
+#include "logging.h"
+
 #include <babeltrace/compat/utc-internal.h>
 #include <babeltrace/plugin/plugin-dev.h>
 #include <babeltrace/graph/component.h>
@@ -305,7 +308,7 @@ enum bt_component_status init_from_params(struct trimmer *trimmer,
                value_ret = bt_value_bool_get(value, &gmt);
                if (value_ret) {
                        ret = BT_COMPONENT_STATUS_INVALID;
-                       printf_error("Failed to retrieve clock-gmt value. Expecting a boolean");
+                       BT_LOGE_STR("Failed to retrieve clock-gmt value. Expecting a boolean");
                }
        }
        bt_put(value);
@@ -322,7 +325,7 @@ enum bt_component_status init_from_params(struct trimmer *trimmer,
                if (value_ret || timestamp_from_arg(str,
                                trimmer, &trimmer->begin, gmt)) {
                        ret = BT_COMPONENT_STATUS_INVALID;
-                       printf_error("Failed to retrieve begin value. Expecting a timestamp string");
+                       BT_LOGE_STR("Failed to retrieve begin value. Expecting a timestamp string");
                }
        }
        bt_put(value);
@@ -339,14 +342,14 @@ enum bt_component_status init_from_params(struct trimmer *trimmer,
                if (value_ret || timestamp_from_arg(str,
                                trimmer, &trimmer->end, gmt)) {
                        ret = BT_COMPONENT_STATUS_INVALID;
-                       printf_error("Failed to retrieve end value. Expecting a timestamp string");
+                       BT_LOGE_STR("Failed to retrieve end value. Expecting a timestamp string");
                }
        }
        bt_put(value);
 end:
        if (trimmer->begin.set && trimmer->end.set) {
                if (trimmer->begin.value > trimmer->end.value) {
-                       printf_error("Unexpected: time range begin value is above end value");
+                       BT_LOGE_STR("Unexpected: time range begin value is above end value");
                        ret = BT_COMPONENT_STATUS_INVALID;
                }
        }
This page took 0.040532 seconds and 4 git commands to generate.