From: Philippe Proulx Date: Sat, 15 Jun 2019 02:41:01 +0000 (-0400) Subject: src.text.dmesg: honor component's initial log level X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=caedbbee1a3660b373e29f8de2bea716e837ffca src.text.dmesg: honor component's initial log level Signed-off-by: Philippe Proulx Change-Id: Ibf940cce2980389241ee6f4790c4c651280918a5 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1463 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- diff --git a/src/cli/babeltrace2.c b/src/cli/babeltrace2.c index 9a631c92..679439a5 100644 --- a/src/cli/babeltrace2.c +++ b/src/cli/babeltrace2.c @@ -62,7 +62,6 @@ static const char* log_level_env_var_names[] = { "BABELTRACE_SINK_TEXT_DETAILS_LOG_LEVEL", "BABELTRACE_SRC_CTF_FS_LOG_LEVEL", "BABELTRACE_SRC_CTF_LTTNG_LIVE_LOG_LEVEL", - "BABELTRACE_SRC_TEXT_DMESG_LOG_LEVEL", NULL, }; diff --git a/src/plugins/text/dmesg/Makefile.am b/src/plugins/text/dmesg/Makefile.am index 6f168b38..5c0c6783 100644 --- a/src/plugins/text/dmesg/Makefile.am +++ b/src/plugins/text/dmesg/Makefile.am @@ -3,6 +3,4 @@ noinst_LTLIBRARIES = libbabeltrace2-plugin-text-dmesg-cc.la # ctf-text plugin libbabeltrace2_plugin_text_dmesg_cc_la_SOURCES = \ dmesg.c \ - dmesg.h \ - logging.h \ - logging.c + dmesg.h diff --git a/src/plugins/text/dmesg/dmesg.c b/src/plugins/text/dmesg/dmesg.c index 476b0803..f681b229 100644 --- a/src/plugins/text/dmesg/dmesg.c +++ b/src/plugins/text/dmesg/dmesg.c @@ -21,17 +21,17 @@ * SOFTWARE. */ +#define BT_LOG_OUTPUT_LEVEL (dmesg_comp->log_level) #define BT_LOG_TAG "PLUGIN/SRC.TEXT.DMESG" -#include "logging.h" +#include "logging/log.h" #include #include #include #include -#include "common/assert.h" #include "common/common.h" +#include "common/assert.h" #include -#include "lib/value.h" #include "compat/utc.h" #include "compat/stdio.h" #include @@ -65,6 +65,8 @@ struct dmesg_msg_iter { }; struct dmesg_component { + bt_logging_level log_level; + struct { GString *path; bt_bool read_from_stdin; @@ -82,7 +84,8 @@ struct dmesg_component { }; static -bt_field_class *create_event_payload_fc(bt_trace_class *trace_class) +bt_field_class *create_event_payload_fc(struct dmesg_component *dmesg_comp, + bt_trace_class *trace_class) { bt_field_class *root_fc = NULL; bt_field_class *fc = NULL; @@ -181,7 +184,7 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) goto error; } - fc = create_event_payload_fc(dmesg_comp->trace_class); + fc = create_event_payload_fc(dmesg_comp, dmesg_comp->trace_class); if (!fc) { BT_LOGE_STR("Cannot create event payload field class."); goto error; @@ -388,12 +391,18 @@ bt_self_component_status dmesg_init( int ret = 0; struct dmesg_component *dmesg_comp = g_new0(struct dmesg_component, 1); bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; + const bt_component *comp = bt_self_component_as_component( + bt_self_component_source_as_self_component(self_comp)); + bt_logging_level log_level = bt_component_get_logging_level(comp); if (!dmesg_comp) { - BT_LOGE_STR("Failed to allocate one dmesg component structure."); + /* Implicit log level is not available here */ + BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG, + "Failed to allocate one dmesg component structure."); goto error; } + dmesg_comp->log_level = log_level; dmesg_comp->self_comp = self_comp; dmesg_comp->params.path = g_string_new(NULL); if (!dmesg_comp->params.path) { @@ -424,6 +433,8 @@ bt_self_component_status dmesg_init( bt_self_component_set_data( bt_self_component_source_as_self_component(self_comp), dmesg_comp); + BT_LOGI("`src.text.dmesg` component initialized: name=\"%s\"", + bt_component_get_name(comp)); goto end; error: @@ -550,8 +561,8 @@ end: } static -int fill_event_payload_from_line(const char *line, - bt_event *event) +int fill_event_payload_from_line(struct dmesg_component *dmesg_comp, + const char *line, bt_event *event) { bt_field *ep_field = NULL; bt_field *str_field = NULL; @@ -599,6 +610,7 @@ static bt_message *create_msg_from_line( struct dmesg_msg_iter *dmesg_msg_iter, const char *line) { + struct dmesg_component *dmesg_comp = dmesg_msg_iter->dmesg_comp; bt_event *event = NULL; bt_message *msg = NULL; const char *new_start; @@ -613,7 +625,7 @@ bt_message *create_msg_from_line( event = bt_message_event_borrow_event(msg); BT_ASSERT(event); - ret = fill_event_payload_from_line(new_start, event); + ret = fill_event_payload_from_line(dmesg_comp, new_start, event); if (ret) { BT_LOGE("Cannot fill event payload field from line: " "ret=%d", ret); @@ -632,6 +644,8 @@ end: static void destroy_dmesg_msg_iter(struct dmesg_msg_iter *dmesg_msg_iter) { + struct dmesg_component *dmesg_comp = dmesg_msg_iter->dmesg_comp; + if (!dmesg_msg_iter) { return; } @@ -655,7 +669,8 @@ bt_self_message_iterator_status dmesg_msg_iter_init( bt_self_component_source *self_comp, bt_self_component_port_output *self_port) { - struct dmesg_component *dmesg_comp; + struct dmesg_component *dmesg_comp = bt_self_component_get_data( + bt_self_component_source_as_self_component(self_comp)); struct dmesg_msg_iter *dmesg_msg_iter = g_new0(struct dmesg_msg_iter, 1); bt_self_message_iterator_status status = @@ -666,8 +681,6 @@ bt_self_message_iterator_status dmesg_msg_iter_init( goto error; } - dmesg_comp = bt_self_component_get_data( - bt_self_component_source_as_self_component(self_comp)); BT_ASSERT(dmesg_comp); dmesg_msg_iter->dmesg_comp = dmesg_comp; dmesg_msg_iter->pc_msg_iter = self_msg_iter; diff --git a/src/plugins/text/dmesg/logging.c b/src/plugins/text/dmesg/logging.c deleted file mode 100644 index cf042507..00000000 --- a/src/plugins/text/dmesg/logging.c +++ /dev/null @@ -1,27 +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_plugin_text_dmesg_log_level -#include "logging/log.h" - -BT_LOG_INIT_LOG_LEVEL(bt_plugin_text_dmesg_log_level, - "BABELTRACE_SRC_TEXT_DMESG_LOG_LEVEL"); diff --git a/src/plugins/text/dmesg/logging.h b/src/plugins/text/dmesg/logging.h deleted file mode 100644 index 1facad3e..00000000 --- a/src/plugins/text/dmesg/logging.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef PLUGINS_TEXT_DMESG_LOG_LEVEL -#define PLUGINS_TEXT_DMESG_LOG_LEVEL - -/* - * 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_text_dmesg_log_level -#include "logging/log.h" - -BT_LOG_LEVEL_EXTERN_SYMBOL(bt_plugin_text_dmesg_log_level); - -#endif /* PLUGINS_TEXT_DMESG_LOG_LEVEL */