src.text.dmesg: honor component's initial log level
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 15 Jun 2019 02:41:01 +0000 (22:41 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 20 Jun 2019 18:01:16 +0000 (14:01 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ibf940cce2980389241ee6f4790c4c651280918a5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1463
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/cli/babeltrace2.c
src/plugins/text/dmesg/Makefile.am
src/plugins/text/dmesg/dmesg.c
src/plugins/text/dmesg/logging.c [deleted file]
src/plugins/text/dmesg/logging.h [deleted file]

index 9a631c92b71230e3b84f15f660fd0f7e224d3afa..679439a562ca07835890767b2dcdb3f3247d32d8 100644 (file)
@@ -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,
 };
 
index 6f168b38e9672f39526793fe1ede500e3231aab5..5c0c67839900e08ca195ab9e2e84a6ca85e81b07 100644 (file)
@@ -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
index 476b08039875738bd8940f8bb596bf0cdeb2c0fb..f681b229d5275d4371b0e83846dc6dd0328ac81d 100644 (file)
  * 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 <stdbool.h>
 #include <string.h>
 #include <ctype.h>
 #include <stdio.h>
-#include "common/assert.h"
 #include "common/common.h"
+#include "common/assert.h"
 #include <babeltrace2/babeltrace.h>
-#include "lib/value.h"
 #include "compat/utc.h"
 #include "compat/stdio.h"
 #include <glib.h>
@@ -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 (file)
index cf04250..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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_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 (file)
index 1facad3..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef PLUGINS_TEXT_DMESG_LOG_LEVEL
-#define PLUGINS_TEXT_DMESG_LOG_LEVEL
-
-/*
- * 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_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 */
This page took 0.029524 seconds and 4 git commands to generate.