lib: set component's initial log level when adding it to the graph
[babeltrace.git] / src / cli / babeltrace2.c
index b78eebe08573e700e525650282c794a312500512..7da507126553af5449bbffb63c65ea2adafb32a4 100644 (file)
@@ -1782,7 +1782,8 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component(
                        ctx->connect_ports = false;
                        graph_status = bt_graph_add_filter_component(
                                ctx->graph, trimmer_class, trimmer_name,
-                               trimmer_params, &trimmer);
+                               trimmer_params, ctx->cfg->log_level,
+                               &trimmer);
                        free(trimmer_name);
                        if (graph_status != BT_GRAPH_STATUS_OK) {
                                goto error;
@@ -2394,19 +2395,19 @@ int cmd_run_ctx_create_components_from_config_components(
                case BT_COMPONENT_CLASS_TYPE_SOURCE:
                        ret = bt_graph_add_source_component(ctx->graph,
                                comp_cls, cfg_comp->instance_name->str,
-                               cfg_comp->params,
+                               cfg_comp->params, ctx->cfg->log_level,
                                (void *) &comp);
                        break;
                case BT_COMPONENT_CLASS_TYPE_FILTER:
                        ret = bt_graph_add_filter_component(ctx->graph,
                                comp_cls, cfg_comp->instance_name->str,
-                               cfg_comp->params,
+                               cfg_comp->params, ctx->cfg->log_level,
                                (void *) &comp);
                        break;
                case BT_COMPONENT_CLASS_TYPE_SINK:
                        ret = bt_graph_add_sink_component(ctx->graph,
                                comp_cls, cfg_comp->instance_name->str,
-                               cfg_comp->params,
+                               cfg_comp->params, ctx->cfg->log_level,
                                (void *) &comp);
                        break;
                default:
@@ -2753,10 +2754,10 @@ void set_auto_log_levels(struct bt_config *cfg)
         */
        if (getenv("BABELTRACE_DEBUG") &&
                        strcmp(getenv("BABELTRACE_DEBUG"), "1") == 0) {
-               cfg->log_level = 'V';
+               cfg->log_level = BT_LOG_VERBOSE;
        } else if (getenv("BABELTRACE_VERBOSE") &&
                        strcmp(getenv("BABELTRACE_VERBOSE"), "1") == 0) {
-               cfg->log_level = 'I';
+               cfg->log_level = BT_LOG_INFO;
        }
 
        /*
@@ -2771,39 +2772,15 @@ void set_auto_log_levels(struct bt_config *cfg)
         */
        if (!getenv("BABELTRACE_LOGGING_GLOBAL_LEVEL")) {
                if (cfg->verbose) {
-                       bt_logging_set_global_level(BT_LOGGING_LEVEL_INFO);
+                       bt_logging_set_global_level(BT_LOG_INFO);
                } else if (cfg->debug) {
-                       bt_logging_set_global_level(BT_LOGGING_LEVEL_VERBOSE);
+                       bt_logging_set_global_level(BT_LOG_VERBOSE);
                } else {
                        /*
                         * Set library's default log level if not
                         * explicitly specified.
                         */
-                       switch (cfg->log_level) {
-                       case 'N':
-                               bt_logging_set_global_level(BT_LOGGING_LEVEL_NONE);
-                               break;
-                       case 'V':
-                               bt_logging_set_global_level(BT_LOGGING_LEVEL_VERBOSE);
-                               break;
-                       case 'D':
-                               bt_logging_set_global_level(BT_LOGGING_LEVEL_DEBUG);
-                               break;
-                       case 'I':
-                               bt_logging_set_global_level(BT_LOGGING_LEVEL_INFO);
-                               break;
-                       case 'W':
-                               bt_logging_set_global_level(BT_LOGGING_LEVEL_WARN);
-                               break;
-                       case 'E':
-                               bt_logging_set_global_level(BT_LOGGING_LEVEL_ERROR);
-                               break;
-                       case 'F':
-                               bt_logging_set_global_level(BT_LOGGING_LEVEL_FATAL);
-                               break;
-                       default:
-                               abort();
-                       }
+                       bt_logging_set_global_level(cfg->log_level);
                }
        }
 
@@ -2817,31 +2794,7 @@ void set_auto_log_levels(struct bt_config *cfg)
                         * Set CLI's default log level if not explicitly
                         * specified.
                         */
-                       switch (cfg->log_level) {
-                       case 'N':
-                               bt_cli_log_level = BT_LOG_NONE;
-                               break;
-                       case 'V':
-                               bt_cli_log_level = BT_LOG_VERBOSE;
-                               break;
-                       case 'D':
-                               bt_cli_log_level = BT_LOG_DEBUG;
-                               break;
-                       case 'I':
-                               bt_cli_log_level = BT_LOG_INFO;
-                               break;
-                       case 'W':
-                               bt_cli_log_level = BT_LOG_WARN;
-                               break;
-                       case 'E':
-                               bt_cli_log_level = BT_LOG_ERROR;
-                               break;
-                       case 'F':
-                               bt_cli_log_level = BT_LOG_FATAL;
-                               break;
-                       default:
-                               abort();
-                       }
+                       bt_cli_log_level = cfg->log_level;
                }
        }
 
@@ -2860,7 +2813,8 @@ void set_auto_log_levels(struct bt_config *cfg)
                                 * Set module's default log level if not
                                 * explicitly specified.
                                 */
-                               val[0] = cfg->log_level;
+                               val[0] = bt_log_get_letter_from_level(
+                                       cfg->log_level);
                                g_setenv(*env_var_name, val, 1);
                        }
                }
This page took 0.027208 seconds and 4 git commands to generate.