From b4565e8b2e0f7c0e356919fe95b760bed7a71d1b Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 14 Jun 2017 16:30:31 -0400 Subject: [PATCH] Remove legacy printf_verbose()/printf_debug() and others MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jérémie Galarneau --- cli/babeltrace-cfg-cli-args.c | 12 +-- cli/babeltrace.c | 19 ++++- common/Makefile.am | 2 +- common/common.c | 19 +++-- common/logging.c | 26 ++++++ common/logging.h | 31 +++++++ include/babeltrace/babeltrace-internal.h | 104 ----------------------- lib/babeltrace.c | 11 --- plugins/lttng-utils/Makefile.am | 6 +- plugins/lttng-utils/bin-info.c | 22 ++--- plugins/lttng-utils/debug-info.c | 5 +- plugins/lttng-utils/logging.c | 27 ++++++ plugins/lttng-utils/logging.h | 31 +++++++ plugins/lttng-utils/plugin.c | 13 +-- plugins/text/Makefile.am | 3 +- plugins/utils/trimmer/Makefile.am | 8 +- plugins/utils/trimmer/iterator.c | 19 +++-- plugins/utils/trimmer/logging.c | 27 ++++++ plugins/utils/trimmer/logging.h | 31 +++++++ plugins/utils/trimmer/trimmer.c | 11 ++- 20 files changed, 264 insertions(+), 163 deletions(-) create mode 100644 common/logging.c create mode 100644 common/logging.h create mode 100644 plugins/lttng-utils/logging.c create mode 100644 plugins/lttng-utils/logging.h create mode 100644 plugins/utils/trimmer/logging.c create mode 100644 plugins/utils/trimmer/logging.h diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c index 541329ab..65334db6 100644 --- a/cli/babeltrace-cfg-cli-args.c +++ b/cli/babeltrace-cfg-cli-args.c @@ -22,6 +22,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "CLI-CFG-CLI-ARGS" +#include "logging.h" + #include #include #include @@ -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; } diff --git a/cli/babeltrace.c b/cli/babeltrace.c index 668491e7..3c44db35 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -65,11 +65,14 @@ * 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 diff --git a/common/Makefile.am b/common/Makefile.am index a4543ddc..4c902fa4 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -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 diff --git a/common/common.c b/common/common.c index 96532e2b..0a0d1583 100644 --- a/common/common.c +++ b/common/common.c @@ -22,6 +22,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "COMMON" +#include "logging.h" + #include #include #include @@ -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 index 00000000..6e520d25 --- /dev/null +++ b/common/logging.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017 Philippe Proulx + * + * 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 + +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 index 00000000..c5b8e5e2 --- /dev/null +++ b/common/logging.h @@ -0,0 +1,31 @@ +#ifndef COMMON_LOGGING_H +#define COMMON_LOGGING_H + +/* + * Copyright (c) 2017 Philippe Proulx + * + * 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 + +BT_LOG_LEVEL_EXTERN_SYMBOL(bt_common_log_level); + +#endif /* COMMON_LOGGING_H */ diff --git a/include/babeltrace/babeltrace-internal.h b/include/babeltrace/babeltrace-internal.h index 006bf8f3..1bdd79ec 100644 --- a/include/babeltrace/babeltrace-internal.h +++ b/include/babeltrace/babeltrace-internal.h @@ -34,110 +34,6 @@ #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) diff --git a/lib/babeltrace.c b/lib/babeltrace.c index 2b675eb2..ab2b6bc8 100644 --- a/lib/babeltrace.c +++ b/lib/babeltrace.c @@ -30,17 +30,6 @@ #include #include -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; diff --git a/plugins/lttng-utils/Makefile.am b/plugins/lttng-utils/Makefile.am index 8f0975d6..7d731996 100644 --- a/plugins/lttng-utils/Makefile.am +++ b/plugins/lttng-utils/Makefile.am @@ -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 diff --git a/plugins/lttng-utils/bin-info.c b/plugins/lttng-utils/bin-info.c index 170b351f..689d5ad4 100644 --- a/plugins/lttng-utils/bin-info.c +++ b/plugins/lttng-utils/bin-info.c @@ -26,6 +26,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "PLUGIN-CTF-LTTNG-UTILS-DEBUG-INFO-FLT-BIN-INFO" +#include "logging.h" + #include #include #include @@ -37,7 +40,6 @@ #include #include #include -#include #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; diff --git a/plugins/lttng-utils/debug-info.c b/plugins/lttng-utils/debug-info.c index 2ac4002f..493898fd 100644 --- a/plugins/lttng-utils/debug-info.c +++ b/plugins/lttng-utils/debug-info.c @@ -25,6 +25,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "PLUGIN-CTF-LTTNG-UTILS-DEBUG-INFO-FLT" +#include "logging.h" + #include #include #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 index 00000000..3b57447f --- /dev/null +++ b/plugins/lttng-utils/logging.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Philippe Proulx + * + * 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 + +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 index 00000000..b77a02f9 --- /dev/null +++ b/plugins/lttng-utils/logging.h @@ -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 + * + * 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 + +BT_LOG_LEVEL_EXTERN_SYMBOL(bt_plugin_lttng_utils_debug_info_log_level); + +#endif /* PLUGINS_LTTNG_UTILS_DEBUG_INFO_LOGGING_H */ diff --git a/plugins/lttng-utils/plugin.c b/plugins/lttng-utils/plugin.c index 9436ee34..1b63b8db 100644 --- a/plugins/lttng-utils/plugin.c +++ b/plugins/lttng-utils/plugin.c @@ -26,6 +26,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "PLUGIN-CTF-LTTNG-UTILS-DEBUG-INFO-FLT" +#include "logging.h" + #include #include #include @@ -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"); } diff --git a/plugins/text/Makefile.am b/plugins/text/Makefile.am index 99364c5a..03de922d 100644 --- a/plugins/text/Makefile.am +++ b/plugins/text/Makefile.am @@ -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 diff --git a/plugins/utils/trimmer/Makefile.am b/plugins/utils/trimmer/Makefile.am index 74bad1c9..db1ca0f9 100644 --- a/plugins/utils/trimmer/Makefile.am +++ b/plugins/utils/trimmer/Makefile.am @@ -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 diff --git a/plugins/utils/trimmer/iterator.c b/plugins/utils/trimmer/iterator.c index 1e94b15e..73b95ba7 100644 --- a/plugins/utils/trimmer/iterator.c +++ b/plugins/utils/trimmer/iterator.c @@ -26,6 +26,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "PLUGIN-UTILS-TRIMMER-FLT" +#include "logging.h" + #include #include #include @@ -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 index 00000000..fffefdac --- /dev/null +++ b/plugins/utils/trimmer/logging.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Philippe Proulx + * + * 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 + +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 index 00000000..d5ef128a --- /dev/null +++ b/plugins/utils/trimmer/logging.h @@ -0,0 +1,31 @@ +#ifndef PLUGINS_UTILS_TRIMMER_LOGGING_H +#define PLUGINS_UTILS_TRIMMER_LOGGING_H + +/* + * Copyright (c) 2017 Philippe Proulx + * + * 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 + +BT_LOG_LEVEL_EXTERN_SYMBOL(bt_plugin_utils_trimmer_log_level); + +#endif /* PLUGINS_UTILS_TRIMMER_LOGGING_H */ diff --git a/plugins/utils/trimmer/trimmer.c b/plugins/utils/trimmer/trimmer.c index 2a8bd5e0..d3460fbb 100644 --- a/plugins/utils/trimmer/trimmer.c +++ b/plugins/utils/trimmer/trimmer.c @@ -26,6 +26,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "PLUGIN-UTILS-TRIMMER-FLT" +#include "logging.h" + #include #include #include @@ -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; } } -- 2.34.1