static
void init_log_level(void)
{
- enum bt_logging_level log_level = BT_LOG_NONE;
- const char *log_level_env = getenv("BABELTRACE_CLI_LOG_LEVEL");
-
- if (!log_level_env) {
- goto set_level;
- }
-
- if (strcmp(log_level_env, "VERBOSE") == 0) {
- log_level = BT_LOGGING_LEVEL_VERBOSE;
- } else if (strcmp(log_level_env, "DEBUG") == 0) {
- log_level = BT_LOGGING_LEVEL_DEBUG;
- } else if (strcmp(log_level_env, "INFO") == 0) {
- log_level = BT_LOGGING_LEVEL_INFO;
- } else if (strcmp(log_level_env, "WARN") == 0) {
- log_level = BT_LOGGING_LEVEL_WARN;
- } else if (strcmp(log_level_env, "ERROR") == 0) {
- log_level = BT_LOGGING_LEVEL_ERROR;
- } else if (strcmp(log_level_env, "FATAL") == 0) {
- log_level = BT_LOGGING_LEVEL_FATAL;
- } else if (strcmp(log_level_env, "NONE") == 0) {
- log_level = BT_LOGGING_LEVEL_NONE;
- }
-
-set_level:
- bt_cli_log_level = log_level;
+ bt_cli_log_level = bt_log_get_level_from_env("BABELTRACE_CLI_LOG_LEVEL");
}
void set_sigint_handler(void)
#ifndef BABELTRACE_LOGGING_INTERNAL_H
#define BABELTRACE_LOGGING_INTERNAL_H
+#include <stdlib.h>
+#include <stdio.h>
#include <babeltrace/logging.h>
/* To detect incompatible changes you can define BT_LOG_VERSION_REQUIRED to be
*/
#define BT_LOG_STDERR (&_bt_log_stderr_spec)
+static inline
+int bt_log_get_level_from_env(const char *var)
+{
+ const char *varval = getenv(var);
+ int level = BT_LOG_NONE;
+
+ if (!varval) {
+ goto end;
+ }
+
+ if (strcmp(varval, "VERBOSE") == 0 ||
+ strcmp(varval, "V") == 0) {
+ level = BT_LOG_VERBOSE;
+ } else if (strcmp(varval, "DEBUG") == 0 ||
+ strcmp(varval, "D") == 0) {
+ level = BT_LOG_DEBUG;
+ } else if (strcmp(varval, "INFO") == 0 ||
+ strcmp(varval, "I") == 0) {
+ level = BT_LOG_INFO;
+ } else if (strcmp(varval, "WARN") == 0 ||
+ strcmp(varval, "WARNING") == 0 ||
+ strcmp(varval, "W") == 0) {
+ level = BT_LOG_WARN;
+ } else if (strcmp(varval, "ERROR") == 0 ||
+ strcmp(varval, "E") == 0) {
+ level = BT_LOG_ERROR;
+ } else if (strcmp(varval, "FATAL") == 0 ||
+ strcmp(varval, "F") == 0) {
+ level = BT_LOG_FATAL;
+ } else if (strcmp(varval, "NONE") == 0 ||
+ strcmp(varval, "N") == 0) {
+ level = BT_LOG_NONE;
+ } else {
+ /* Should we warn here? How? */
+ }
+
+end:
+ return level;
+}
+
#ifdef __cplusplus
}
#endif
static
void __attribute__((constructor)) bt_logging_ctor(void)
{
- enum bt_logging_level log_level = BT_LOG_NONE;
- const char *log_level_env = getenv("BABELTRACE_LOGGING_GLOBAL_LEVEL");
const char *v_extra = bt_version_get_extra() ? bt_version_get_extra() :
"";
- if (!log_level_env) {
- goto set_level;
- }
-
- if (strcmp(log_level_env, "VERBOSE") == 0) {
- log_level = BT_LOGGING_LEVEL_VERBOSE;
- } else if (strcmp(log_level_env, "DEBUG") == 0) {
- log_level = BT_LOGGING_LEVEL_DEBUG;
- } else if (strcmp(log_level_env, "INFO") == 0) {
- log_level = BT_LOGGING_LEVEL_INFO;
- } else if (strcmp(log_level_env, "WARN") == 0) {
- log_level = BT_LOGGING_LEVEL_WARN;
- } else if (strcmp(log_level_env, "ERROR") == 0) {
- log_level = BT_LOGGING_LEVEL_ERROR;
- } else if (strcmp(log_level_env, "FATAL") == 0) {
- log_level = BT_LOGGING_LEVEL_FATAL;
- }
-
-set_level:
- bt_logging_set_global_level(log_level);
+ bt_logging_set_global_level(
+ bt_log_get_level_from_env("BABELTRACE_LOGGING_GLOBAL_LEVEL"));
BT_LOGI("Babeltrace %d.%d.%d%s library loaded: "
"major=%d, minor=%d, patch=%d, extra=\"%s\"",
bt_version_get_major(), bt_version_get_minor(),
static
void __attribute__((constructor)) bt_lttng_live_logging_ctor(void)
{
- enum bt_logging_level log_level = BT_LOG_NONE;
- const char *log_level_env = getenv(BT_LOGLEVEL_NAME);
-
- if (!log_level_env) {
- return;
- }
-
- if (strcmp(log_level_env, "VERBOSE") == 0) {
- log_level = BT_LOGGING_LEVEL_VERBOSE;
- } else if (strcmp(log_level_env, "DEBUG") == 0) {
- log_level = BT_LOGGING_LEVEL_DEBUG;
- } else if (strcmp(log_level_env, "INFO") == 0) {
- log_level = BT_LOGGING_LEVEL_INFO;
- } else if (strcmp(log_level_env, "WARN") == 0) {
- log_level = BT_LOGGING_LEVEL_WARN;
- } else if (strcmp(log_level_env, "ERROR") == 0) {
- log_level = BT_LOGGING_LEVEL_ERROR;
- } else if (strcmp(log_level_env, "FATAL") == 0) {
- log_level = BT_LOGGING_LEVEL_FATAL;
- } else {
- bt_lttng_live_log_level = BT_LOGGING_LEVEL_FATAL;
- BT_LOGF("Incorrect log level specified in %s",
- BT_LOGLEVEL_NAME);
- abort();
- }
-
- bt_lttng_live_log_level = log_level;
+ bt_lttng_live_log_level = bt_log_get_level_from_env(BT_LOGLEVEL_NAME);
}