struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
int *retcode, bool force_omit_system_plugin_path,
bool force_omit_home_plugin_path,
- const bt_value *initial_plugin_paths, char *log_level)
+ const bt_value *initial_plugin_paths, int *log_level)
{
poptContext pc = NULL;
char *arg = NULL;
stream_intersection_mode = true;
break;
case OPT_VERBOSE:
- if (*log_level != 'V' && *log_level != 'D') {
- *log_level = 'I';
+ if (*log_level != BT_LOG_VERBOSE &&
+ *log_level != BT_LOG_DEBUG) {
+ *log_level = BT_LOG_INFO;
}
break;
case OPT_DEBUG:
- *log_level = 'V';
+ *log_level = BT_LOG_VERBOSE;
break;
}
/*
* Legacy behaviour: --verbose used to make the `text` output
* format print more information. --verbose is now equivalent to
- * the INFO log level, which is why we compare to 'I' here.
+ * the INFO log level, which is why we compare to `BT_LOG_INFO`
+ * here.
*/
- if (*log_level == 'I') {
+ if (*log_level == BT_LOG_INFO) {
append_implicit_component_param(&implicit_text_args,
"verbose", "yes");
}
fprintf(fp, "Use `babeltrace2 COMMAND --help` to show the help of COMMAND.\n");
}
-static
-char log_level_from_arg(const char *arg)
-{
- char level = 'U';
-
- if (strcmp(arg, "VERBOSE") == 0 ||
- strcmp(arg, "V") == 0) {
- level = 'V';
- } else if (strcmp(arg, "DEBUG") == 0 ||
- strcmp(arg, "D") == 0) {
- level = 'D';
- } else if (strcmp(arg, "INFO") == 0 ||
- strcmp(arg, "I") == 0) {
- level = 'I';
- } else if (strcmp(arg, "WARN") == 0 ||
- strcmp(arg, "WARNING") == 0 ||
- strcmp(arg, "W") == 0) {
- level = 'W';
- } else if (strcmp(arg, "ERROR") == 0 ||
- strcmp(arg, "E") == 0) {
- level = 'E';
- } else if (strcmp(arg, "FATAL") == 0 ||
- strcmp(arg, "F") == 0) {
- level = 'F';
- } else if (strcmp(arg, "NONE") == 0 ||
- strcmp(arg, "N") == 0) {
- level = 'N';
- }
-
- return level;
-}
-
struct bt_config *bt_config_cli_args_create(int argc, const char *argv[],
int *retcode, bool force_omit_system_plugin_path,
bool force_omit_home_plugin_path,
const char **command_argv = NULL;
int command_argc = -1;
const char *command_name = NULL;
- char log_level = 'U';
+ int log_level = -1;
enum command_type {
COMMAND_TYPE_NONE = -1,
if (strcmp(cur_arg, "-d") == 0 ||
strcmp(cur_arg, "--debug") == 0) {
- log_level = 'V';
+ log_level = BT_LOG_VERBOSE;
} else if (strcmp(cur_arg, "-v") == 0 ||
strcmp(cur_arg, "--verbose") == 0) {
- if (log_level != 'V' && log_level != 'D') {
+ if (log_level != BT_LOG_VERBOSE &&
+ log_level != BT_LOG_DEBUG) {
/*
* Legacy: do not override a previous
* --debug because --verbose and --debug
* case we want the lowest log level to
* apply, VERBOSE).
*/
- log_level = 'I';
+ log_level = BT_LOG_INFO;
}
} else if (strcmp(cur_arg, "--log-level") == 0 ||
strcmp(cur_arg, "-l") == 0) {
goto end;
}
- log_level = log_level_from_arg(next_arg);
- if (log_level == 'U') {
+ log_level = bt_log_get_level_from_string(next_arg);
+ if (log_level < 0) {
printf_err("Invalid argument for --log-level option:\n %s\n",
next_arg);
*retcode = 1;
} else if (strncmp(cur_arg, "--log-level=", 12) == 0) {
const char *arg = &cur_arg[12];
- log_level = log_level_from_arg(arg);
- if (log_level == 'U') {
+ log_level = bt_log_get_level_from_string(arg);
+ if (log_level < 0) {
printf_err("Invalid argument for --log-level option:\n %s\n",
arg);
*retcode = 1;
} else if (strncmp(cur_arg, "-l", 2) == 0) {
const char *arg = &cur_arg[2];
- log_level = log_level_from_arg(arg);
- if (log_level == 'U') {
+ log_level = bt_log_get_level_from_string(arg);
+ if (log_level < 0) {
printf_err("Invalid argument for --log-level option:\n %s\n",
arg);
*retcode = 1;
}
if (config) {
- if (log_level == 'U') {
- log_level = 'W';
+ if (log_level < 0) {
+ /* Default log level */
+ log_level = BT_LOG_WARN;
}
config->log_level = log_level;
*/
if (getenv("BABELTRACE_DEBUG") &&
strcmp(getenv("BABELTRACE_DEBUG"), "1") == 0) {
- cfg->log_level = 'V';
+ cfg->log_level = BT_LOG_VERBOSE;
} else if (getenv("BABELTRACE_VERBOSE") &&
strcmp(getenv("BABELTRACE_VERBOSE"), "1") == 0) {
- cfg->log_level = 'I';
+ cfg->log_level = BT_LOG_INFO;
}
/*
*/
if (!getenv("BABELTRACE_LOGGING_GLOBAL_LEVEL")) {
if (cfg->verbose) {
- bt_logging_set_global_level(BT_LOGGING_LEVEL_INFO);
+ bt_logging_set_global_level(BT_LOG_INFO);
} else if (cfg->debug) {
- bt_logging_set_global_level(BT_LOGGING_LEVEL_VERBOSE);
+ bt_logging_set_global_level(BT_LOG_VERBOSE);
} else {
/*
* Set library's default log level if not
* explicitly specified.
*/
- switch (cfg->log_level) {
- case 'N':
- bt_logging_set_global_level(BT_LOGGING_LEVEL_NONE);
- break;
- case 'V':
- bt_logging_set_global_level(BT_LOGGING_LEVEL_VERBOSE);
- break;
- case 'D':
- bt_logging_set_global_level(BT_LOGGING_LEVEL_DEBUG);
- break;
- case 'I':
- bt_logging_set_global_level(BT_LOGGING_LEVEL_INFO);
- break;
- case 'W':
- bt_logging_set_global_level(BT_LOGGING_LEVEL_WARN);
- break;
- case 'E':
- bt_logging_set_global_level(BT_LOGGING_LEVEL_ERROR);
- break;
- case 'F':
- bt_logging_set_global_level(BT_LOGGING_LEVEL_FATAL);
- break;
- default:
- abort();
- }
+ bt_logging_set_global_level(cfg->log_level);
}
}
* Set CLI's default log level if not explicitly
* specified.
*/
- switch (cfg->log_level) {
- case 'N':
- bt_cli_log_level = BT_LOG_NONE;
- break;
- case 'V':
- bt_cli_log_level = BT_LOG_VERBOSE;
- break;
- case 'D':
- bt_cli_log_level = BT_LOG_DEBUG;
- break;
- case 'I':
- bt_cli_log_level = BT_LOG_INFO;
- break;
- case 'W':
- bt_cli_log_level = BT_LOG_WARN;
- break;
- case 'E':
- bt_cli_log_level = BT_LOG_ERROR;
- break;
- case 'F':
- bt_cli_log_level = BT_LOG_FATAL;
- break;
- default:
- abort();
- }
+ bt_cli_log_level = cfg->log_level;
}
}
* Set module's default log level if not
* explicitly specified.
*/
- val[0] = cfg->log_level;
+ val[0] = bt_log_get_letter_from_level(
+ cfg->log_level);
g_setenv(*env_var_name, val, 1);
}
}