BT_LOG_INIT_LOG_LEVEL() defines a hidden log level symbol and a static
constructor which initializes this symbol according to the value of
a given environment variable. This macro should be used in a module-wise
dedicated logging source file, `logging.c`, as such:
#define BT_LOG_OUTPUT_LEVEL some_log_level_symbol
#include <babeltrace/logging-internal.h>
BT_LOG_INIT_LOG_LEVEL(some_log_level_symbol, "BABELTRACE_SOME_LOG_LEVEL");
BT_LOG_LEVEL_EXTERN_SYMBOL() declares this symbol as `extern`. It
should be used in a module-wise dedicated logging header, `logging.h`,
as such:
#define BT_LOG_OUTPUT_LEVEL some_log_level_symbol
#include <babeltrace/logging-internal.h>
BT_LOG_LEVEL_EXTERN_SYMBOL(some_log_level_symbol);
Any module source file which contains log statements should use the
following lines **before any #include line**:
#define BT_LOG_TAG "THE-MODULE-TAG"
#include "logging.h"
If there are subdirectories within a module, it is possible that you
need to include "../logging.h" or "../../logging.h", for example. The
rule of thumb is that no module file, except `logging.c`, should include
<babeltrace/logging-internal.h> directly.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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); \
+ }
+
#ifdef __cplusplus
}
#endif
-#endif
+#endif /* BABELTRACE_LOGGING_INTERNAL_H */