Add bt_log_get_level_from_env() and use it
[babeltrace.git] / cli / babeltrace.c
index 124ee53ae54b29ac34c9dc0eabe4ccb42a12f521..9de233bc1672718ec3bc3c31cd029b469a3e0b60 100644 (file)
@@ -366,7 +366,7 @@ void print_value_rec(FILE *fp, struct bt_value *value, size_t indent)
                break;
        }
        default:
-               assert(false);
+               abort();
        }
 }
 
@@ -519,7 +519,7 @@ void print_cfg(struct bt_config *cfg)
                print_cfg_print_lttng_live_sessions(cfg);
                break;
        default:
-               assert(false);
+               abort();
        }
 }
 
@@ -1203,7 +1203,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component(
                 */
                BT_LOGF("Invalid connection: downstream component is a source: "
                        "conn-arg=\"%s\"", cfg_conn->arg->str);
-               assert(false);
+               abort();
        }
 
        downstream_port_count = port_count_fn(downstream_comp);
@@ -1494,25 +1494,29 @@ int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg)
        the_graph = ctx->graph;
        ret = bt_graph_add_port_added_listener(ctx->graph,
                graph_port_added_listener, ctx);
-       if (ret) {
+       if (ret < 0) {
+               BT_LOGE_STR("Cannot add \"port added\" listener to graph.");
                goto error;
        }
 
        ret = bt_graph_add_port_removed_listener(ctx->graph,
                graph_port_removed_listener, ctx);
-       if (ret) {
+       if (ret < 0) {
+               BT_LOGE_STR("Cannot add \"port removed\" listener to graph.");
                goto error;
        }
 
        ret = bt_graph_add_ports_connected_listener(ctx->graph,
                graph_ports_connected_listener, ctx);
-       if (ret) {
+       if (ret < 0) {
+               BT_LOGE_STR("Cannot add \"ports connected\" listener to graph.");
                goto error;
        }
 
        ret = bt_graph_add_ports_disconnected_listener(ctx->graph,
                graph_ports_disconnected_listener, ctx);
-       if (ret) {
+       if (ret < 0) {
+               BT_LOGE_STR("Cannot add \"ports disconnected\" listener to graph.");
                goto error;
        }
 
@@ -1564,7 +1568,7 @@ int cmd_run_ctx_create_components_from_config_components(
                        cfg_comp->instance_name->str, cfg_comp->params);
                if (!comp) {
                        BT_LOGE("Cannot create component: plugin-name=\"%s\", "
-                               "comp-cls-name=\"%s\", comp-cls-type=%d",
+                               "comp-cls-name=\"%s\", comp-cls-type=%d, "
                                "comp-name=\"%s\"",
                                cfg_comp->plugin_name->str,
                                cfg_comp->comp_cls_name->str,
@@ -1732,6 +1736,13 @@ int cmd_run(struct bt_config *cfg)
                goto error;
        }
 
+       if (canceled) {
+               BT_LOGI_STR("Canceled by user before creating components.");
+               goto error;
+       }
+
+       BT_LOGI_STR("Creating components.");
+
        /* Create the requested component instances */
        if (cmd_run_ctx_create_components(&ctx)) {
                BT_LOGE_STR("Cannot create components.");
@@ -1739,6 +1750,13 @@ int cmd_run(struct bt_config *cfg)
                goto error;
        }
 
+       if (canceled) {
+               BT_LOGI_STR("Canceled by user before connecting components.");
+               goto error;
+       }
+
+       BT_LOGI_STR("Connecting components.");
+
        /* Connect the initially visible component ports */
        if (cmd_run_ctx_connect_ports(&ctx)) {
                BT_LOGE_STR("Cannot connect initial component ports.");
@@ -1747,7 +1765,8 @@ int cmd_run(struct bt_config *cfg)
        }
 
        if (canceled) {
-               goto end;
+               BT_LOGI_STR("Canceled by user before running the graph.");
+               goto error;
        }
 
        BT_LOGI_STR("Running the graph.");
@@ -1756,6 +1775,13 @@ int cmd_run(struct bt_config *cfg)
        while (true) {
                enum bt_graph_status graph_status = bt_graph_run(ctx.graph);
 
+               /*
+                * Reset console in case something messed with console
+                * codes during the graph's execution.
+                */
+               printf("%s", bt_common_color_reset());
+               fflush(stdout);
+               fprintf(stderr, "%s", bt_common_color_reset());
                BT_LOGV("bt_graph_run() returned: status=%s",
                        bt_graph_status_str(graph_status));
 
@@ -1834,31 +1860,7 @@ void warn_command_name_and_directory_clash(struct bt_config *cfg)
 static
 void init_log_level(void)
 {
-       enum bt_logging_level log_level = BT_LOG_NONE;
-       const char *log_level_env = getenv("BABELTRACE_CLI_LOG_LEVEL");
-
-       if (!log_level_env) {
-               goto set_level;
-       }
-
-       if (strcmp(log_level_env, "VERBOSE") == 0) {
-               log_level = BT_LOGGING_LEVEL_VERBOSE;
-       } else if (strcmp(log_level_env, "DEBUG") == 0) {
-               log_level = BT_LOGGING_LEVEL_DEBUG;
-       } else if (strcmp(log_level_env, "INFO") == 0) {
-               log_level = BT_LOGGING_LEVEL_INFO;
-       } else if (strcmp(log_level_env, "WARN") == 0) {
-               log_level = BT_LOGGING_LEVEL_WARN;
-       } else if (strcmp(log_level_env, "ERROR") == 0) {
-               log_level = BT_LOGGING_LEVEL_ERROR;
-       } else if (strcmp(log_level_env, "FATAL") == 0) {
-               log_level = BT_LOGGING_LEVEL_FATAL;
-       } else if (strcmp(log_level_env, "NONE") == 0) {
-               log_level = BT_LOGGING_LEVEL_NONE;
-       }
-
-set_level:
-       bt_cli_log_level = log_level;
+       bt_cli_log_level = bt_log_get_level_from_env("BABELTRACE_CLI_LOG_LEVEL");
 }
 
 void set_sigint_handler(void)
@@ -1955,8 +1957,8 @@ int main(int argc, const char **argv)
                ret = cmd_print_lttng_live_sessions(cfg);
                break;
        default:
-               BT_LOGF("Invalid command: cmd=%d", cfg->command);
-               assert(false);
+               BT_LOGF("Invalid/unknown command: cmd=%d", cfg->command);
+               abort();
        }
 
        BT_LOGI("Command completed: cmd=%d, command-name=\"%s\", ret=%d",
This page took 0.027188 seconds and 4 git commands to generate.