autodisc: make it possible to interrupt auto source discovery
[babeltrace.git] / src / cli / babeltrace2.c
index 11f63494bc074c6cdc8b858c97c06987652e6a12..de0b6c2b7ef99c41e752fa4222c88c50bad00f83 100644 (file)
 #include "babeltrace2-cfg.h"
 #include "babeltrace2-cfg-cli-args.h"
 #include "babeltrace2-cfg-cli-args-default.h"
+#include "babeltrace2-log-level.h"
 #include "babeltrace2-plugins.h"
 #include "babeltrace2-query.h"
 
 #define ENV_BABELTRACE_WARN_COMMAND_NAME_DIRECTORY_CLASH "BABELTRACE_CLI_WARN_COMMAND_NAME_DIRECTORY_CLASH"
-#define ENV_BABELTRACE_CLI_LOG_LEVEL "BABELTRACE_CLI_LOG_LEVEL"
 #define NSEC_PER_SEC   1000000000LL
 
-/*
- * Known environment variable names for the log levels of the project's
- * modules.
- */
-static const char* log_level_env_var_names[] = {
-       "BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL",
-       "BABELTRACE_PYTHON_BT2_LOG_LEVEL",
-       NULL,
-};
-
 /* Application's interrupter (owned by this) */
 static bt_interrupter *the_interrupter;
 
@@ -569,8 +559,6 @@ void print_cfg(struct bt_config *cfg)
        }
 
        BT_LOGI_STR("CLI configuration:");
-       BT_LOGI("  Debug mode: %s\n", cfg->debug ? "yes" : "no");
-       BT_LOGI("  Verbose mode: %s\n", cfg->verbose ? "yes" : "no");
 
        switch (cfg->command) {
        case BT_CONFIG_COMMAND_RUN:
@@ -993,7 +981,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                        BT_CLI_LOGE_APPEND_CAUSE("Missing `timer-us` entry.");
                        goto error;
                }
-               timer_us = bt_value_integer_signed_get(v);
+               timer_us = bt_value_integer_unsigned_get(v);
                fprintf(out_stream, " (timer = %" PRIu64 ", ", timer_us);
                v = bt_value_map_borrow_entry_value_const(map, "stream-count");
                if (!v) {
@@ -1001,7 +989,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                                "Missing `stream-count` entry.");
                        goto error;
                }
-               streams = bt_value_integer_signed_get(v);
+               streams = bt_value_integer_unsigned_get(v);
                fprintf(out_stream, "%" PRIu64 " stream(s), ", streams);
                v = bt_value_map_borrow_entry_value_const(map, "client-count");
                if (!v) {
@@ -1009,7 +997,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                                "Missing `client-count` entry.");
                        goto error;
                }
-               clients = bt_value_integer_signed_get(v);
+               clients = bt_value_integer_unsigned_get(v);
                fprintf(out_stream, "%" PRIu64 " client(s) connected)\n", clients);
        }
 
@@ -2494,87 +2482,6 @@ void init_log_level(void)
        bt_cli_log_level = bt_log_get_level_from_env(ENV_BABELTRACE_CLI_LOG_LEVEL);
 }
 
-static
-void set_auto_log_levels(struct bt_config *cfg)
-{
-       const char **env_var_name;
-
-       /*
-        * Override the configuration's default log level if
-        * BABELTRACE_VERBOSE or BABELTRACE_DEBUG environment variables
-        * are found for backward compatibility with legacy Babetrace 1.
-        */
-       if (getenv("BABELTRACE_DEBUG") &&
-                       strcmp(getenv("BABELTRACE_DEBUG"), "1") == 0) {
-               cfg->log_level = BT_LOG_TRACE;
-       } else if (getenv("BABELTRACE_VERBOSE") &&
-                       strcmp(getenv("BABELTRACE_VERBOSE"), "1") == 0) {
-               cfg->log_level = BT_LOG_INFO;
-       }
-
-       /*
-        * Set log levels according to --debug or --verbose. For
-        * backward compatibility, --debug is more verbose than
-        * --verbose. So:
-        *
-        *     --verbose: INFO log level
-        *     --debug:   TRACE log level (includes DEBUG, which is
-        *                is less verbose than TRACE in the internal
-        *                logging framework)
-        */
-       if (!getenv("LIBBABELTRACE2_INIT_LOG_LEVEL")) {
-               if (cfg->verbose) {
-                       bt_logging_set_global_level(BT_LOG_INFO);
-               } else if (cfg->debug) {
-                       bt_logging_set_global_level(BT_LOG_TRACE);
-               } else {
-                       /*
-                        * Set library's default log level if not
-                        * explicitly specified.
-                        */
-                       bt_logging_set_global_level(cfg->log_level);
-               }
-       }
-
-       if (!getenv(ENV_BABELTRACE_CLI_LOG_LEVEL)) {
-               if (cfg->verbose) {
-                       bt_cli_log_level = BT_LOG_INFO;
-               } else if (cfg->debug) {
-                       bt_cli_log_level = BT_LOG_TRACE;
-               } else {
-                       /*
-                        * Set CLI's default log level if not explicitly
-                        * specified.
-                        */
-                       bt_cli_log_level = cfg->log_level;
-               }
-       }
-
-       env_var_name = log_level_env_var_names;
-
-       while (*env_var_name) {
-               if (!getenv(*env_var_name)) {
-                       if (cfg->verbose) {
-                               g_setenv(*env_var_name, "INFO", 1);
-                       } else if (cfg->debug) {
-                               g_setenv(*env_var_name, "TRACE", 1);
-                       } else {
-                               char val[2] = { 0 };
-
-                               /*
-                                * Set module's default log level if not
-                                * explicitly specified.
-                                */
-                               val[0] = bt_log_get_letter_from_level(
-                                       cfg->log_level);
-                               g_setenv(*env_var_name, val, 1);
-                       }
-               }
-
-               env_var_name++;
-       }
-}
-
 static
 void print_error_causes(void)
 {
@@ -2694,12 +2601,22 @@ int main(int argc, const char **argv)
 {
        int ret;
        int retcode;
-       struct bt_config *cfg;
+       struct bt_config *cfg = NULL;
 
        init_log_level();
        set_signal_handler();
        init_loaded_plugins();
-       cfg = bt_config_cli_args_create_with_default(argc, argv, &retcode);
+
+       BT_ASSERT(!the_interrupter);
+       the_interrupter = bt_interrupter_create();
+       if (!the_interrupter) {
+               BT_CLI_LOGE_APPEND_CAUSE("Failed to create an interrupter object.");
+               retcode = 1;
+               goto end;
+       }
+
+       cfg = bt_config_cli_args_create_with_default(argc, argv, &retcode,
+               the_interrupter);
 
        if (retcode < 0) {
                /* Quit without errors; typically usage/version */
@@ -2716,12 +2633,11 @@ int main(int argc, const char **argv)
 
        if (!cfg) {
                BT_CLI_LOGE_APPEND_CAUSE(
-                       "Failed to create a valid Babeltrace configuration.");
+                       "Failed to create a valid Babeltrace CLI configuration.");
                retcode = 1;
                goto end;
        }
 
-       set_auto_log_levels(cfg);
        print_cfg(cfg);
 
        if (cfg->command_needs_plugins) {
@@ -2734,14 +2650,6 @@ int main(int argc, const char **argv)
                }
        }
 
-       BT_ASSERT(!the_interrupter);
-       the_interrupter = bt_interrupter_create();
-       if (!the_interrupter) {
-               BT_CLI_LOGE_APPEND_CAUSE("Failed to create an interrupter object.");
-               retcode = 1;
-               goto end;
-       }
-
        BT_LOGI("Executing command: cmd=%d, command-name=\"%s\"",
                cfg->command, cfg->command_name);
 
This page took 0.025593 seconds and 4 git commands to generate.