cli: set all the log level of all known loggers with -v and -d
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 9 Jun 2017 21:30:07 +0000 (17:30 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Jun 2017 22:18:17 +0000 (18:18 -0400)
Set log levels according to --debug or --verbose. For
backward compatibility, --debug is more verbose than
--verbose. So:

    --verbose: INFO log level
    --debug:   VERBOSE log level (includes DEBUG, which is
               is less verbose than VERBOSE in the internal
               logging framework)

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
cli/babeltrace-cfg-cli-args.c
cli/babeltrace.c

index 6a711726dd03b43bd9191e59ecebcc376863b565..27514ba41b20f124edda6b690b3ef09ab9f1a4df 100644 (file)
@@ -4703,6 +4703,12 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
        cfg = bt_config_run_from_args_array(run_args, retcode,
                force_omit_system_plugin_path, force_omit_home_plugin_path,
                initial_plugin_paths);
+       if (!cfg) {
+               goto error;
+       }
+
+       cfg->debug = got_debug_opt;
+       cfg->verbose = got_verbose_opt;
        goto end;
 
 error:
index 6cdb8442f146d41891a45efb5e3a1742e3a46022..f91bad771d3e0128c492ca5e61012037dda2af23 100644 (file)
 
 #define ENV_BABELTRACE_WARN_COMMAND_NAME_DIRECTORY_CLASH "BABELTRACE_CLI_WARN_COMMAND_NAME_DIRECTORY_CLASH"
 
+/*
+ * Known environment variable names for the log levels of the project's
+ * modules.
+ */
+static const char* log_level_env_var_names[] = {
+       "BABELTRACE_PLUGIN_CTF_BTR_LOG_LEVEL",
+       "BABELTRACE_PLUGIN_CTF_FS_SRC_LOG_LEVEL",
+       "BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_SRC_LOG_LEVEL",
+       "BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL",
+       "BABELTRACE_PLUGIN_CTF_NOTIF_ITER_LOG_LEVEL",
+       "BABELTRACE_PYTHON_PLUGIN_PROVIDER_LOG_LEVEL",
+       NULL,
+};
+
 /* Application's processing graph (weak) */
 static struct bt_graph *the_graph;
 static bool canceled = false;
@@ -1917,6 +1931,7 @@ int main(int argc, const char **argv)
        int ret;
        int retcode;
        struct bt_config *cfg;
+       const char **env_var_name;
 
        init_log_level();
        set_sigint_handler();
@@ -1942,18 +1957,34 @@ int main(int argc, const char **argv)
                goto end;
        }
 
+       /*
+        * Set log levels according to --debug or --verbose. For
+        * backward compatibility, --debug is more verbose than
+        * --verbose. So:
+        *
+        *     --verbose: INFO log level
+        *     --debug:   VERBOSE log level (includes DEBUG, which is
+        *                is less verbose than VERBOSE in the internal
+        *                logging framework)
+        */
        if (cfg->verbose) {
+               bt_cli_log_level = BT_LOGGING_LEVEL_INFO;
+               bt_logging_set_global_level(BT_LOGGING_LEVEL_INFO);
+       } else if (cfg->debug) {
                bt_cli_log_level = BT_LOGGING_LEVEL_VERBOSE;
                bt_logging_set_global_level(BT_LOGGING_LEVEL_VERBOSE);
-               // TODO: for backward compat., set the log level
-               //       environment variables of the known plugins
-               //       to VERBOSE
-       } else if (cfg->debug) {
-               bt_cli_log_level = BT_LOGGING_LEVEL_DEBUG;
-               bt_logging_set_global_level(BT_LOGGING_LEVEL_DEBUG);
-               // TODO: for backward compat., set the log level
-               //       environment variables of the known plugins
-               //       to DEBUG
+       }
+
+       env_var_name = log_level_env_var_names;
+
+       while (*env_var_name) {
+               if (cfg->verbose) {
+                       setenv(*env_var_name, "I", 1);
+               } else if (cfg->debug) {
+                       setenv(*env_var_name, "V", 1);
+               }
+
+               env_var_name++;
        }
 
        babeltrace_debug = cfg->debug;
This page took 0.033833 seconds and 4 git commands to generate.