#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;
bt_common_color_reset());
break;
case BT_VALUE_TYPE_ARRAY:
- size = bt_value_array_get_size(value);
+ size = bt_value_array_get_length(value);
if (size < 0) {
goto error;
}
}
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:
}
}
- array_size = bt_value_array_get_size(results);
+ array_size = bt_value_array_get_length(results);
for (i = 0; i < array_size; i++) {
const char *url_text;
int64_t timer_us, streams, clients;
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) {
"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) {
"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);
}
goto error;
}
- trace_count = bt_value_array_get_size(query_result);
+ trace_count = bt_value_array_get_length(query_result);
if (trace_count < 0) {
ret = -1;
goto error;
goto error;
}
- stream_count = bt_value_array_get_size(stream_infos);
+ stream_count = bt_value_array_get_length(stream_infos);
if (stream_count < 0) {
ret = -1;
goto error;
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)
{
{
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 */
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) {
}
}
- 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);