From fc11b6a68b415ddd078fdda9ba905b88ddde8c9b Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 9 Jun 2017 17:30:07 -0400 Subject: [PATCH] cli: set all the log level of all known loggers with -v and -d MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jérémie Galarneau --- cli/babeltrace-cfg-cli-args.c | 6 +++++ cli/babeltrace.c | 49 ++++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c index 6a711726..27514ba4 100644 --- a/cli/babeltrace-cfg-cli-args.c +++ b/cli/babeltrace-cfg-cli-args.c @@ -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: diff --git a/cli/babeltrace.c b/cli/babeltrace.c index 6cdb8442..f91bad77 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -59,6 +59,20 @@ #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; -- 2.34.1