From: Philippe Proulx Date: Sat, 15 Jun 2019 03:59:04 +0000 (-0400) Subject: Logging: pass dynamic log level to common functions and subsystems X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=86d8b7b82095055ced36135ecf4336753360cea4 Logging: pass dynamic log level to common functions and subsystems This patch makes the project's common functions and subsystems get a dynamic log level instead of using a global one set from an environment variable. The goal is to achieve per-component log levels, so the common functions and subsystems must receive, eventually, the component's specific log level. "Naked" functions (without a context object of some sort) simply get their log level from a new parameter. In that case `BT_LOG_OUTPUT_LEVEL` is simply defined to `log_level`, so a local `log_level` variable must exist when using logging statements. Subsystems, such as an FD cache or a CTF serializer, get their log level from a new parameter in their initialization function and then use it for their other operations. It was somehow hard to do this for `src/common` alone without also doing it for the rest so I'm doing all of them at once here. For those subsystems, the local `logging.c` and `logging.h` disappear. `tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c` needs to pass a log level to the FD cache subsystem; I used the WARN level instead of setting the log level from an environment variable for this test alone. Signed-off-by: Philippe Proulx Change-Id: I35979a8fe4c74afe5921c3b6651015cd7ee2760a Reviewed-on: https://review.lttng.org/c/babeltrace/+/1460 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- diff --git a/src/cli/babeltrace2-cfg-cli-args.c b/src/cli/babeltrace2-cfg-cli-args.c index cad2b4aa..6e9aac95 100644 --- a/src/cli/babeltrace2-cfg-cli-args.c +++ b/src/cli/babeltrace2-cfg-cli-args.c @@ -1553,8 +1553,8 @@ int append_home_and_system_plugin_paths(bt_value *plugin_paths, if (bt_common_is_setuid_setgid()) { BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary."); } else { - char *home_plugin_dir = - bt_common_get_home_plugin_path(); + char *home_plugin_dir = bt_common_get_home_plugin_path( + BT_LOG_OUTPUT_LEVEL); if (home_plugin_dir) { ret = bt_config_append_plugin_paths( diff --git a/src/cli/babeltrace2.c b/src/cli/babeltrace2.c index d4145f1d..9aa52a87 100644 --- a/src/cli/babeltrace2.c +++ b/src/cli/babeltrace2.c @@ -49,10 +49,6 @@ * modules. */ static const char* log_level_env_var_names[] = { - "BABELTRACE_COMMON_LOG_LEVEL", - "BABELTRACE_COMPAT_LOG_LEVEL", - "BABELTRACE_CTFSER_LOG_LEVEL", - "BABELTRACE_FD_CACHE_LOG_LEVEL", "BABELTRACE_FLT_LTTNG_UTILS_DEBUG_INFO_LOG_LEVEL", "BABELTRACE_FLT_UTILS_COUNTER_LOG_LEVEL", "BABELTRACE_FLT_UTILS_MUXER_LOG_LEVEL", diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 7db98d7a..b2a232e8 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -6,9 +6,7 @@ libbabeltrace2_common_la_SOURCES = \ assert.h \ assert.c \ common.c \ - common.h \ - logging.c \ - logging.h + common.h noinst_HEADERS = \ align.h \ diff --git a/src/common/common.c b/src/common/common.c index 3c48e84f..d5f05062 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -22,8 +22,9 @@ * SOFTWARE. */ +#define BT_LOG_OUTPUT_LEVEL log_level #define BT_LOG_TAG "COMMON" -#include "logging.h" +#include "logging/log.h" #include #include @@ -116,7 +117,7 @@ bool bt_common_is_setuid_setgid(void) #endif /* __MINGW32__ */ static -char *bt_secure_getenv(const char *name) +char *bt_secure_getenv(const char *name, int log_level) { if (bt_common_is_setuid_setgid()) { BT_LOGD("Disregarding environment variable for setuid/setgid binary: " @@ -128,18 +129,18 @@ char *bt_secure_getenv(const char *name) #ifdef __MINGW32__ static -const char *bt_get_home_dir(void) +const char *bt_get_home_dir(int log_level) { return g_get_home_dir(); } #else /* __MINGW32__ */ static -const char *bt_get_home_dir(void) +const char *bt_get_home_dir(int log_level) { char *val = NULL; struct passwd *pwd; - val = bt_secure_getenv(HOME_ENV_VAR); + val = bt_secure_getenv(HOME_ENV_VAR, log_level); if (val) { goto end; } @@ -155,13 +156,13 @@ end: #endif /* __MINGW32__ */ BT_HIDDEN -char *bt_common_get_home_plugin_path(void) +char *bt_common_get_home_plugin_path(int log_level) { char *path = NULL; const char *home_dir; size_t length; - home_dir = bt_get_home_dir(); + home_dir = bt_get_home_dir(log_level); if (!home_dir) { goto end; } @@ -1238,7 +1239,7 @@ end: #endif BT_HIDDEN -size_t bt_common_get_page_size(void) +size_t bt_common_get_page_size(int log_level) { int page_size; diff --git a/src/common/common.h b/src/common/common.h index c62da1a3..8ac99535 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -93,7 +93,7 @@ const char *bt_common_get_system_plugin_path(void); * return value. */ BT_HIDDEN -char *bt_common_get_home_plugin_path(void); +char *bt_common_get_home_plugin_path(int log_level); /* * Appends the list of directories in `paths` to the array `dirs`. @@ -310,7 +310,7 @@ void bt_common_custom_snprintf(char *buf, size_t buf_size, * Returns the system page size. */ BT_HIDDEN -size_t bt_common_get_page_size(void); +size_t bt_common_get_page_size(int log_level); /* * Adds the digit separator `sep` as many times as needed to form groups @@ -334,7 +334,7 @@ void bt_common_sep_digits(char *str, unsigned int digits_per_group, char sep); * value smaller than the requested `count`. */ static inline -ssize_t bt_common_read(int fd, void *buf, size_t count) +ssize_t bt_common_read(int fd, void *buf, size_t count, int log_level) { size_t i = 0; ssize_t ret; @@ -348,15 +348,18 @@ ssize_t bt_common_read(int fd, void *buf, size_t count) ret = read(fd, buf + i, count - i); if (ret < 0) { if (errno == EINTR) { -#ifdef BT_LOGD_STR - BT_LOGD_STR("read() call interrupted; retrying..."); +#ifdef BT_LOG_WRITE_CUR_LVL + BT_LOG_WRITE_CUR_LVL(BT_LOG_DEBUG, log_level, + BT_LOG_TAG, + "read() call interrupted; retrying..."); #endif /* retry operation */ continue; } else { -#ifdef BT_LOGE_ERRNO - BT_LOGE_ERRNO("Error while reading", ": fd=%d", - fd); +#ifdef BT_LOG_WRITE_ERRNO_CUR_LVL + BT_LOG_WRITE_ERRNO_CUR_LVL(BT_LOG_ERROR, + log_level, BT_LOG_TAG, + "Error while reading", ": fd=%d", fd); #endif goto end; } diff --git a/src/common/logging.c b/src/common/logging.c deleted file mode 100644 index 7af804b9..00000000 --- a/src/common/logging.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 "logging/log.h" - -BT_LOG_INIT_LOG_LEVEL(bt_common_log_level, "BABELTRACE_COMMON_LOG_LEVEL"); diff --git a/src/common/logging.h b/src/common/logging.h deleted file mode 100644 index 48e1f7b2..00000000 --- a/src/common/logging.h +++ /dev/null @@ -1,31 +0,0 @@ -#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 "logging/log.h" - -BT_LOG_LEVEL_EXTERN_SYMBOL(bt_common_log_level); - -#endif /* COMMON_LOGGING_H */ diff --git a/src/common/mmap-align.h b/src/common/mmap-align.h index 1bb2b72f..5d91c035 100644 --- a/src/common/mmap-align.h +++ b/src/common/mmap-align.h @@ -72,13 +72,13 @@ off_t get_page_aligned_offset(off_t offset, size_t page_size) static inline struct mmap_align *mmap_align(size_t length, int prot, - int flags, int fd, off_t offset) + int flags, int fd, off_t offset, int log_level) { struct mmap_align *mma; off_t page_aligned_offset; /* mmap offset, aligned to floor */ size_t page_size; - page_size = bt_common_get_page_size(); + page_size = bt_common_get_page_size(log_level); mma = malloc(sizeof(*mma)); if (!mma) diff --git a/src/compat/Makefile.am b/src/compat/Makefile.am index 040ccc8d..939b169b 100644 --- a/src/compat/Makefile.am +++ b/src/compat/Makefile.am @@ -1,8 +1,6 @@ noinst_LTLIBRARIES = libcompat.la libcompat_la_SOURCES = \ - logging.c \ - logging.h \ mman.c \ mman.h \ uuid.c \ diff --git a/src/compat/logging.c b/src/compat/logging.c deleted file mode 100644 index a79cc10f..00000000 --- a/src/compat/logging.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017 Michael Jeanson - * - * 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_compat_log_level -#include "logging/log.h" - -BT_LOG_INIT_LOG_LEVEL(bt_compat_log_level, "BABELTRACE_COMPAT_LOG_LEVEL"); diff --git a/src/compat/logging.h b/src/compat/logging.h deleted file mode 100644 index ccb77a9d..00000000 --- a/src/compat/logging.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef COMPAT_LOGGING_H -#define COMPAT_LOGGING_H - -/* - * Copyright (c) 2017 Michael Jeanson - * - * 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_compat_log_level -#include "logging/log.h" - -BT_LOG_LEVEL_EXTERN_SYMBOL(bt_compat_log_level); - -#endif /* COMPAT_LOGGING_H */ diff --git a/src/compat/mman.c b/src/compat/mman.c index edc59eda..de1d7b34 100644 --- a/src/compat/mman.c +++ b/src/compat/mman.c @@ -26,8 +26,9 @@ * SOFTWARE. */ +#define BT_LOG_OUTPUT_LEVEL (mapping->log_level) #define BT_LOG_TAG "COMPAT/MMAN" -#include "logging.h" +#include "logging/log.h" #include "common/macros.h" @@ -52,6 +53,8 @@ int bt_mman_dummy_symbol; #include "compat/mman.h" struct mmap_mapping { + int log_level; + /* The duplicated handle. */ HANDLE file_handle; /* Handle returned by CreateFileMapping. */ @@ -102,13 +105,18 @@ void addr_clean(void *addr) { /* Cleanup of handles should never fail. */ if (!UnmapViewOfFile(addr)) { - BT_LOGF_STR("Failed to unmap mmap mapping."); + /* + * FIXME: We don't have access to the mapping's log + * level here, so force a FATAL level. + */ + BT_LOG_WRITE_CUR_LVL(BT_LOG_FATAL, BT_LOG_FATAL, BT_LOG_TAG, + "Failed to unmap mmap mapping."); abort(); } } static -void mmap_lock(void) +void mmap_lock(int log_level) { if (pthread_mutex_lock(&mmap_mutex)) { BT_LOGF_STR("Failed to acquire mmap_mutex."); @@ -117,7 +125,7 @@ void mmap_lock(void) } static -void mmap_unlock(void) +void mmap_unlock(int log_level) { if (pthread_mutex_unlock(&mmap_mutex)) { BT_LOGF_STR("Failed to release mmap_mutex."); @@ -163,7 +171,7 @@ DWORD map_prot_flags(int prot, DWORD *dwDesiredAccess) BT_HIDDEN void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd, - off_t offset) + off_t offset, int log_level) { struct mmap_mapping *mapping = NULL; void *mapping_addr; @@ -191,9 +199,10 @@ void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd, } /* Allocate the mapping struct. */ - mapping = mapping_create(); + mapping = mapping_create(log_level); if (!mapping) { - BT_LOGE_STR("Failed to allocate mmap mapping."); + BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG, + "Failed to allocate mmap mapping."); _set_errno(ENOMEM); goto error; } @@ -233,7 +242,7 @@ void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd, goto error; } - mmap_lock(); + mmap_lock(log_level); /* If we have never done any mappings, allocate the hashtable. */ if (!mmap_mappings) { @@ -250,12 +259,12 @@ void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd, /* Add the new mapping to the hashtable. */ g_hash_table_insert(mmap_mappings, mapping_addr, mapping); - mmap_unlock(); + mmap_unlock(log_level); return mapping_addr; error_mutex_unlock: - mmap_unlock(); + mmap_unlock(log_level); error: mapping_clean(mapping); return MAP_FAILED; @@ -265,8 +274,12 @@ BT_HIDDEN int bt_munmap(void *addr, size_t length) { int ret = 0; + struct mmap_mapping *mapping = addr; + int log_level; - mmap_lock(); + BT_ASSERT(mapping); + log_level = mapping->log_level; + mmap_lock(log_level); /* Check if the mapping exists in the hashtable. */ if (g_hash_table_lookup(mmap_mappings, addr) == NULL) { @@ -282,7 +295,7 @@ int bt_munmap(void *addr, size_t length) } end: - mmap_unlock(); + mmap_unlock(log_level); return ret; } diff --git a/src/compat/uuid.c b/src/compat/uuid.c index 547a7921..1f60939a 100644 --- a/src/compat/uuid.c +++ b/src/compat/uuid.c @@ -22,9 +22,6 @@ * SOFTWARE. */ -#define BT_LOG_TAG "COMPAT/UUID" -#include "logging.h" - #ifdef __APPLE__ /* * On macOS, we need a dummy symbol so that the linker won't diff --git a/src/ctf-writer/stream.c b/src/ctf-writer/stream.c index e456dcfb..c7540264 100644 --- a/src/ctf-writer/stream.c +++ b/src/ctf-writer/stream.c @@ -1026,7 +1026,8 @@ append_ids: goto end; } - ret = bt_ctfser_init(&stream->ctfser, file_path); + ret = bt_ctfser_init(&stream->ctfser, file_path, + BT_LOG_OUTPUT_LEVEL); g_free(file_path); if (ret) { /* bt_ctfser_init() logs errors */ diff --git a/src/ctfser/Makefile.am b/src/ctfser/Makefile.am index e6ae86f5..c56e75cd 100644 --- a/src/ctfser/Makefile.am +++ b/src/ctfser/Makefile.am @@ -4,6 +4,4 @@ noinst_LTLIBRARIES = libbabeltrace2-ctfser.la libbabeltrace2_ctfser_la_SOURCES = \ ctfser.c \ - ctfser.h \ - logging.c \ - logging.h + ctfser.h diff --git a/src/ctfser/ctfser.c b/src/ctfser/ctfser.c index 6043db32..b28845cf 100644 --- a/src/ctfser/ctfser.c +++ b/src/ctfser/ctfser.c @@ -20,8 +20,9 @@ * SOFTWARE. */ +#define BT_LOG_OUTPUT_LEVEL (ctfser->log_level) #define BT_LOG_TAG "CTFSER" -#include "logging.h" +#include "logging/log.h" #include #include @@ -44,9 +45,9 @@ #include "compat/fcntl.h" static inline -uint64_t get_packet_size_increment_bytes(void) +uint64_t get_packet_size_increment_bytes(struct bt_ctfser *ctfser) { - return bt_common_get_page_size() * 8; + return bt_common_get_page_size(ctfser->log_level) * 8; } static inline @@ -54,7 +55,7 @@ void mmap_align_ctfser(struct bt_ctfser *ctfser) { ctfser->base_mma = mmap_align(ctfser->cur_packet_size_bytes, PROT_READ | PROT_WRITE, - MAP_SHARED, ctfser->fd, ctfser->mmap_offset); + MAP_SHARED, ctfser->fd, ctfser->mmap_offset, ctfser->log_level); } BT_HIDDEN @@ -77,7 +78,8 @@ int _bt_ctfser_increase_cur_packet_size(struct bt_ctfser *ctfser) goto end; } - ctfser->cur_packet_size_bytes += get_packet_size_increment_bytes(); + ctfser->cur_packet_size_bytes += get_packet_size_increment_bytes( + ctfser); do { ret = bt_posix_fallocate(ctfser->fd, ctfser->mmap_offset, @@ -110,7 +112,7 @@ end: } BT_HIDDEN -int bt_ctfser_init(struct bt_ctfser *ctfser, const char *path) +int bt_ctfser_init(struct bt_ctfser *ctfser, const char *path, int log_level) { int ret = 0; @@ -118,6 +120,7 @@ int bt_ctfser_init(struct bt_ctfser *ctfser, const char *path) memset(ctfser, 0, sizeof(*ctfser)); ctfser->fd = open(path, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + ctfser->log_level = log_level; if (ctfser->fd < 0) { BT_LOGW_ERRNO("Failed to open stream file for writing", ": path=\"%s\", ret=%d", @@ -220,7 +223,8 @@ int bt_ctfser_open_packet(struct bt_ctfser *ctfser) ctfser->prev_packet_size_bytes = 0; /* Make initial space for the current packet */ - ctfser->cur_packet_size_bytes = get_packet_size_increment_bytes(); + ctfser->cur_packet_size_bytes = get_packet_size_increment_bytes( + ctfser); do { ret = bt_posix_fallocate(ctfser->fd, ctfser->mmap_offset, diff --git a/src/ctfser/ctfser.h b/src/ctfser/ctfser.h index c59af924..f8bbfae2 100644 --- a/src/ctfser/ctfser.h +++ b/src/ctfser/ctfser.h @@ -72,6 +72,9 @@ struct bt_ctfser { /* Stream file's path (for debugging) */ GString *path; + + /* Serializer's log level */ + int log_level; }; /* @@ -80,7 +83,8 @@ struct bt_ctfser { * This function opens the file `path` for writing. */ BT_HIDDEN -int bt_ctfser_init(struct bt_ctfser *ctfser, const char *path); +int bt_ctfser_init(struct bt_ctfser *ctfser, const char *path, + int log_level); /* * Finalizes a CTF serializer. diff --git a/src/ctfser/logging.c b/src/ctfser/logging.c deleted file mode 100644 index 779078d6..00000000 --- a/src/ctfser/logging.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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_ctfser_log_level -#include "logging/log.h" - -BT_LOG_INIT_LOG_LEVEL(bt_ctfser_log_level, "BABELTRACE_CTFSER_LOG_LEVEL"); diff --git a/src/ctfser/logging.h b/src/ctfser/logging.h deleted file mode 100644 index 547f1ac1..00000000 --- a/src/ctfser/logging.h +++ /dev/null @@ -1,31 +0,0 @@ -#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_ctfser_log_level -#include "logging/log.h" - -BT_LOG_LEVEL_EXTERN_SYMBOL(bt_ctfser_log_level); - -#endif /* COMMON_LOGGING_H */ diff --git a/src/fd-cache/Makefile.am b/src/fd-cache/Makefile.am index c4a12882..804a1a17 100644 --- a/src/fd-cache/Makefile.am +++ b/src/fd-cache/Makefile.am @@ -4,6 +4,4 @@ noinst_LTLIBRARIES = libbabeltrace2-fd-cache.la libbabeltrace2_fd_cache_la_SOURCES = \ fd-cache.c \ - fd-cache.h \ - logging.c \ - logging.h + fd-cache.h diff --git a/src/fd-cache/fd-cache.c b/src/fd-cache/fd-cache.c index cb1472b9..9a742a45 100644 --- a/src/fd-cache/fd-cache.c +++ b/src/fd-cache/fd-cache.c @@ -26,8 +26,9 @@ * SOFTWARE. */ +#define BT_LOG_OUTPUT_LEVEL (fdc->log_level) #define BT_LOG_TAG "FD-CACHE" -#include "logging.h" +#include "logging/log.h" #include #include @@ -102,10 +103,11 @@ void file_key_destroy(gpointer data) } BT_HIDDEN -int bt_fd_cache_init(struct bt_fd_cache *fdc) +int bt_fd_cache_init(struct bt_fd_cache *fdc, int log_level) { int ret = 0; + fdc->log_level = log_level; fdc->cache = g_hash_table_new_full(file_key_hash, file_key_equal, file_key_destroy, (GDestroyNotify) fd_cache_handle_internal_destroy); if (!fdc->cache) { diff --git a/src/fd-cache/fd-cache.h b/src/fd-cache/fd-cache.h index 977aaf4d..7a935b8f 100644 --- a/src/fd-cache/fd-cache.h +++ b/src/fd-cache/fd-cache.h @@ -35,6 +35,7 @@ struct bt_fd_cache_handle { }; struct bt_fd_cache { + int log_level; GHashTable *cache; }; @@ -45,7 +46,7 @@ int bt_fd_cache_handle_get_fd(struct bt_fd_cache_handle *handle) } BT_HIDDEN -int bt_fd_cache_init(struct bt_fd_cache *fdc); +int bt_fd_cache_init(struct bt_fd_cache *fdc, int log_level); BT_HIDDEN void bt_fd_cache_fini(struct bt_fd_cache *fdc); diff --git a/src/fd-cache/logging.c b/src/fd-cache/logging.c deleted file mode 100644 index 875f3bae..00000000 --- a/src/fd-cache/logging.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2019 Francis Deslauriers - * - * 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_fd_cache_log_level -#include "logging/log.h" - -BT_LOG_INIT_LOG_LEVEL(bt_fd_cache_log_level, "BABELTRACE_FD_CACHE_LOG_LEVEL"); diff --git a/src/fd-cache/logging.h b/src/fd-cache/logging.h deleted file mode 100644 index 89a783b9..00000000 --- a/src/fd-cache/logging.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef FD_CACHE_LOGGING_H -#define FD_CACHE_LOGGING_H - -/* - * Copyright (c) 2019 Francis Deslauriers - * - * 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_fd_cache_log_level -#include "logging/log.h" - -BT_LOG_LEVEL_EXTERN_SYMBOL(bt_fd_cache_log_level); - -#endif /* FD_CACHE_LOGGING_H */ diff --git a/src/lib/plugin/plugin.c b/src/lib/plugin/plugin.c index 30c10ed2..94594386 100644 --- a/src/lib/plugin/plugin.c +++ b/src/lib/plugin/plugin.c @@ -214,7 +214,7 @@ const struct bt_plugin *bt_plugin_find(const char *plugin_name) } } - home_plugin_dir = bt_common_get_home_plugin_path(); + home_plugin_dir = bt_common_get_home_plugin_path(BT_LOG_OUTPUT_LEVEL); if (home_plugin_dir) { GString *home_plugin_dir_str = g_string_new(home_plugin_dir); diff --git a/src/plugins/ctf/fs-sink/fs-sink-stream.c b/src/plugins/ctf/fs-sink/fs-sink-stream.c index 41098dc7..52da0acf 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-stream.c +++ b/src/plugins/ctf/fs-sink/fs-sink-stream.c @@ -168,7 +168,7 @@ struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace, set_stream_file_name(stream); g_string_append_printf(path, "/%s", stream->file_name->str); - ret = bt_ctfser_init(&stream->ctfser, path->str); + ret = bt_ctfser_init(&stream->ctfser, path->str, BT_LOG_OUTPUT_LEVEL); if (ret) { goto error; } diff --git a/src/plugins/ctf/fs-src/data-stream-file.c b/src/plugins/ctf/fs-src/data-stream-file.c index 1a451925..c3ae979c 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.c +++ b/src/plugins/ctf/fs-src/data-stream-file.c @@ -222,7 +222,8 @@ enum bt_msg_iter_medium_status medop_seek(enum bt_msg_iter_seek_whence whence, if (ds_file->mmap_addr && (offset < ds_file->mmap_offset || offset >= ds_file->mmap_offset + ds_file->mmap_len)) { int unmap_ret; - off_t offset_in_mapping = offset % bt_common_get_page_size(); + off_t offset_in_mapping = offset % + bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL); BT_LOGD("Medium seek request cannot be accomodated by the current " "file mapping: offset=%jd, mmap-offset=%jd, " @@ -608,7 +609,7 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create( bt_stream *stream, const char *path) { int ret; - const size_t page_size = bt_common_get_page_size(); + const size_t page_size = bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL); struct ctf_fs_ds_file *ds_file = g_new0(struct ctf_fs_ds_file, 1); if (!ds_file) { diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c index d0a729b6..4530248d 100644 --- a/src/plugins/ctf/fs-src/fs.c +++ b/src/plugins/ctf/fs-src/fs.c @@ -260,7 +260,7 @@ bt_self_message_iterator_status ctf_fs_iterator_init( msg_iter_data->pc_msg_iter = self_msg_iter; msg_iter_data->msg_iter = bt_msg_iter_create( port_data->ds_file_group->ctf_fs_trace->metadata->tc, - bt_common_get_page_size() * 8, + bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL) * 8, ctf_fs_ds_file_medops, NULL); if (!msg_iter_data->msg_iter) { BT_LOGE_STR("Cannot create a CTF message iterator."); @@ -721,7 +721,8 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, struct bt_msg_iter_packet_properties props; msg_iter = bt_msg_iter_create(ctf_fs_trace->metadata->tc, - bt_common_get_page_size() * 8, ctf_fs_ds_file_medops, NULL); + bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL) * 8, + ctf_fs_ds_file_medops, NULL); if (!msg_iter) { BT_LOGE_STR("Cannot create a CTF message iterator."); goto error; diff --git a/src/plugins/lttng-utils/debug-info/debug-info.c b/src/plugins/lttng-utils/debug-info/debug-info.c index 8fee09ab..9f6f0968 100644 --- a/src/plugins/lttng-utils/debug-info/debug-info.c +++ b/src/plugins/lttng-utils/debug-info/debug-info.c @@ -1995,7 +1995,8 @@ bt_self_message_iterator_status debug_info_msg_iter_init( goto error; } - ret = bt_fd_cache_init(&debug_info_msg_iter->fd_cache); + ret = bt_fd_cache_init(&debug_info_msg_iter->fd_cache, + BT_LOG_OUTPUT_LEVEL); if (ret) { status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM; goto error; diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c index d681ef56..c55201c1 100644 --- a/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c +++ b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c @@ -21,6 +21,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define BT_LOG_OUTPUT_LEVEL BT_LOG_WARN +#define BT_LOG_TAG "TEST/BIN-INFO" +#include "logging/log.h" + #include #include #include @@ -223,7 +227,7 @@ void test_bin_info_build_id(const char *bin_info_dir) exit(EXIT_FAILURE); } - ret = bt_fd_cache_init(&fdc); + ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL); if (ret != 0) { diag("Failed to initialize FD cache"); exit(EXIT_FAILURE); @@ -277,7 +281,7 @@ void test_bin_info_debug_link(const char *bin_info_dir) exit(EXIT_FAILURE); } - ret = bt_fd_cache_init(&fdc); + ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL); if (ret != 0) { diag("Failed to initialize FD cache"); exit(EXIT_FAILURE); @@ -327,7 +331,7 @@ void test_bin_info_elf(const char *bin_info_dir) exit(EXIT_FAILURE); } - ret = bt_fd_cache_init(&fdc); + ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL); if (ret != 0) { diag("Failed to initialize FD cache"); exit(EXIT_FAILURE); @@ -375,7 +379,7 @@ void test_bin_info_bundled(const char *bin_info_dir) exit(EXIT_FAILURE); } - ret = bt_fd_cache_init(&fdc); + ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL); if (ret != 0) { diag("Failed to initialize FD cache"); exit(EXIT_FAILURE);