+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;
+}
+
+#define BT_LOG_LEVEL_EXTERN_SYMBOL(_level_sym) \
+ extern int _level_sym
+
+#define BT_LOG_INIT_LOG_LEVEL(_level_sym, _env_var) \
+ BT_HIDDEN int _level_sym = BT_LOG_NONE; \
+ static \
+ void __attribute__((constructor)) _bt_log_level_ctor(void) \
+ { \
+ _level_sym = bt_log_get_level_from_env(_env_var); \
+ }
+