From 86f21ef32d1d44a79a9950da257502b974656e90 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 31 May 2017 13:01:36 -0400 Subject: [PATCH] python-plugin-provider: use standard logging files and macros MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- python-plugin-provider/Makefile.am | 3 +- python-plugin-provider/logging.c | 27 ++++++++++++++++ python-plugin-provider/logging.h | 31 +++++++++++++++++++ .../python-plugin-provider.c | 16 +--------- 4 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 python-plugin-provider/logging.c create mode 100644 python-plugin-provider/logging.h diff --git a/python-plugin-provider/Makefile.am b/python-plugin-provider/Makefile.am index 00884e1e..145c46f3 100644 --- a/python-plugin-provider/Makefile.am +++ b/python-plugin-provider/Makefile.am @@ -2,7 +2,8 @@ AM_CFLAGS = $(PYTHON_INCLUDE) $(PACKAGE_CFLAGS) -I$(top_srcdir)/include lib_LTLIBRARIES = libbabeltrace-python-plugin-provider.la -libbabeltrace_python_plugin_provider_la_SOURCES = python-plugin-provider.c +libbabeltrace_python_plugin_provider_la_SOURCES = \ + python-plugin-provider.c logging.c logging.h libbabeltrace_python_plugin_provider_la_LDFLAGS = \ -version-info $(BABELTRACE_LIBRARY_VERSION) $(PYTHON_LIBS) diff --git a/python-plugin-provider/logging.c b/python-plugin-provider/logging.c new file mode 100644 index 00000000..c6ba4381 --- /dev/null +++ b/python-plugin-provider/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 python_plugin_provider_log_level +#include + +BT_LOG_INIT_LOG_LEVEL(python_plugin_provider_log_level, + "BABELTRACE_PYTHON_PLUGIN_PROVIDER_LOG_LEVEL"); diff --git a/python-plugin-provider/logging.h b/python-plugin-provider/logging.h new file mode 100644 index 00000000..d5ab7ef4 --- /dev/null +++ b/python-plugin-provider/logging.h @@ -0,0 +1,31 @@ +#ifndef PYTHON_PLUGIN_PROVIDER_LOGGING_H +#define PYTHON_PLUGIN_PROVIDER_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 python_plugin_provider_log_level +#include + +BT_LOG_LEVEL_EXTERN_SYMBOL(python_plugin_provider_log_level); + +#endif /* PYTHON_PLUGIN_PROVIDER_LOGGING_H */ diff --git a/python-plugin-provider/python-plugin-provider.c b/python-plugin-provider/python-plugin-provider.c index c276aadf..26ada1ba 100644 --- a/python-plugin-provider/python-plugin-provider.c +++ b/python-plugin-provider/python-plugin-provider.c @@ -24,15 +24,8 @@ * SOFTWARE. */ -#define BT_LOG_OUTPUT_LEVEL python_plugin_provider_log_level #define BT_LOG_TAG "PLUGIN-PY" -#include - -/* - * Must be before the rest because some of the headers below could - * contain logging statements which need this symbol when expanded. - */ -static int python_plugin_provider_log_level = BT_LOG_NONE; +#include "logging.h" #include #include @@ -65,13 +58,6 @@ enum python_state { static PyObject *py_try_load_plugin_module_func = NULL; -static -void __attribute__((constructor)) logging_ctor(void) -{ - python_plugin_provider_log_level = - bt_log_get_level_from_env("BABELTRACE_PYTHON_PLUGIN_PROVIDER_LOG_LEVEL"); -} - static void print_python_traceback_warn(void) { -- 2.34.1