-#endif
-
-/* Execute log statement if condition is true. Example:
- *
- * BT_LOG_IF(1 < 2, BT_LOGI("Log this"));
- * BT_LOG_IF(1 > 2, BT_LOGI("Don't log this"));
- *
- * Keep in mind though, that if condition can't be evaluated at compile time,
- * then it will be evaluated at run time. This will increase exectuable size
- * and can have noticeable performance overhead. Try to limit conditions to
- * expressions that can be evaluated at compile time.
- */
-#define BT_LOG_IF(cond, f) do { _BT_LOG_IF((cond)) { f; } } _BT_LOG_ONCE
-
-/* Mark log statement as "secret". Log statements that are marked as secrets
- * will NOT be executed when censoring is enabled (see BT_LOG_CENSORED).
- * Example:
- *
- * BT_LOG_SECRET(BT_LOGI("Credit card: %s", credit_card));
- * BT_LOG_SECRET(BT_LOGD_MEM(cipher, cipher_sz, "Cipher bytes:"));
- */
-#define BT_LOG_SECRET(f) BT_LOG_IF(BT_LOG_SECRETS, f)
-
-/* Check "current" log level at compile time (ignoring "output" log level).
- * Evaluates to true when specified log level is enabled. For example:
- *
- * #if BT_LOG_ENABLED_DEBUG
- * const char *const g_enum_strings[] = {
- * "enum_value_0", "enum_value_1", "enum_value_2"
- * };
- * #endif
- * // ...
- * #if BT_LOG_ENABLED_DEBUG
- * BT_LOGD("enum value: %s", g_enum_strings[v]);
- * #endif
- *
- * See BT_MINIMAL_LOG_LEVEL for details.
- */
-#define BT_LOG_ENABLED(lvl) ((lvl) >= _BT_MINIMAL_LOG_LEVEL)
-#define BT_LOG_ENABLED_TRACE BT_LOG_ENABLED(BT_LOG_TRACE)
-#define BT_LOG_ENABLED_DEBUG BT_LOG_ENABLED(BT_LOG_DEBUG)
-#define BT_LOG_ENABLED_INFO BT_LOG_ENABLED(BT_LOG_INFO)
-#define BT_LOG_ENABLED_WARNING BT_LOG_ENABLED(BT_LOG_WARNING)
-#define BT_LOG_ENABLED_ERROR BT_LOG_ENABLED(BT_LOG_ERROR)
-#define BT_LOG_ENABLED_FATAL BT_LOG_ENABLED(BT_LOG_FATAL)
-
-/* Check "output" log level at run time (taking into account "current" log
- * level as well). Evaluates to true when specified log level is turned on AND
- * enabled. For example:
- *
- * if (BT_LOG_ON_DEBUG)
- * {
- * char hash[65];
- * sha256(data_ptr, data_sz, hash);
- * BT_LOGD("data: len=%u, sha256=%s", data_sz, hash);
- * }
- *
- * See BT_LOG_OUTPUT_LEVEL for details.
- */
-#define BT_LOG_ON_CUR_LVL(lvl, cur_lvl) \
- G_UNLIKELY(BT_LOG_ENABLED((lvl)) && (lvl) >= (cur_lvl))
-#define BT_LOG_ON(lvl) \
- G_UNLIKELY(BT_LOG_ENABLED((lvl)) && (lvl) >= _BT_LOG_OUTPUT_LEVEL)
-#define BT_LOG_ON_TRACE BT_LOG_ON(BT_LOG_TRACE)
-#define BT_LOG_ON_DEBUG BT_LOG_ON(BT_LOG_DEBUG)
-#define BT_LOG_ON_INFO BT_LOG_ON(BT_LOG_INFO)
-#define BT_LOG_ON_WARNING BT_LOG_ON(BT_LOG_WARNING)
-#define BT_LOG_ON_ERROR BT_LOG_ON(BT_LOG_ERROR)
-#define BT_LOG_ON_FATAL BT_LOG_ON(BT_LOG_FATAL)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const char *_bt_log_tag_prefix;
-extern bt_log_format _bt_log_global_format;
-extern bt_log_output _bt_log_global_output;
-extern int _bt_log_global_output_lvl;
-extern const bt_log_spec _bt_log_stderr_spec;
-
-void _bt_log_write_d(
- const char *const func, const char *const file, const unsigned line,
- const int lvl, const char *const tag,
- const char *const fmt, ...) _BT_LOG_PRINTFLIKE(6, 7);
-
-void _bt_log_write_aux_d(
- const char *const func, const char *const file, const unsigned line,
- const bt_log_spec *const log, const int lvl, const char *const tag,
- const char *const fmt, ...) _BT_LOG_PRINTFLIKE(7, 8);
-
-void _bt_log_write(
- const int lvl, const char *const tag,
- const char *const fmt, ...) _BT_LOG_PRINTFLIKE(3, 4);
-
-void _bt_log_write_aux(
- const bt_log_spec *const log, const int lvl, const char *const tag,
- const char *const fmt, ...) _BT_LOG_PRINTFLIKE(4, 5);
-
-void _bt_log_write_mem_d(
- const char *const func, const char *const file, const unsigned line,
- const int lvl, const char *const tag,
- const void *const d, const unsigned d_sz,
- const char *const fmt, ...) _BT_LOG_PRINTFLIKE(8, 9);
-
-void _bt_log_write_mem_aux_d(
- const char *const func, const char *const file, const unsigned line,
- const bt_log_spec *const log, const int lvl, const char *const tag,
- const void *const d, const unsigned d_sz,
- const char *const fmt, ...) _BT_LOG_PRINTFLIKE(9, 10);
-
-void _bt_log_write_mem(
- const int lvl, const char *const tag,
- const void *const d, const unsigned d_sz,
- const char *const fmt, ...) _BT_LOG_PRINTFLIKE(5, 6);
-
-void _bt_log_write_mem_aux(
- const bt_log_spec *const log, const int lvl, const char *const tag,
- const void *const d, const unsigned d_sz,
- const char *const fmt, ...) _BT_LOG_PRINTFLIKE(6, 7);
-
-#ifdef __cplusplus
-}
-#endif
-
-/* Message logging macros:
- * - BT_LOGT("format string", args, ...)
- * - BT_LOGD("format string", args, ...)
- * - BT_LOGI("format string", args, ...)
- * - BT_LOGW("format string", args, ...)
- * - BT_LOGE("format string", args, ...)
- * - BT_LOGF("format string", args, ...)
- *
- * Message and error string (errno) logging macros:
- * - BT_LOGT_ERRNO("initial message", "format string", args, ...)
- * - BT_LOGD_ERRNO("initial message", "format string", args, ...)
- * - BT_LOGI_ERRNO("initial message", "format string", args, ...)
- * - BT_LOGW_ERRNO("initial message", "format string", args, ...)
- * - BT_LOGE_ERRNO("initial message", "format string", args, ...)
- * - BT_LOGF_ERRNO("initial message", "format string", args, ...)
- *
- * Memory logging macros:
- * - BT_LOGT_MEM(data_ptr, data_sz, "format string", args, ...)
- * - BT_LOGD_MEM(data_ptr, data_sz, "format string", args, ...)
- * - BT_LOGI_MEM(data_ptr, data_sz, "format string", args, ...)
- * - BT_LOGW_MEM(data_ptr, data_sz, "format string", args, ...)
- * - BT_LOGE_MEM(data_ptr, data_sz, "format string", args, ...)
- * - BT_LOGF_MEM(data_ptr, data_sz, "format string", args, ...)
- *
- * Auxiliary logging macros:
- * - BT_LOGT_AUX(&log_instance, "format string", args, ...)
- * - BT_LOGD_AUX(&log_instance, "format string", args, ...)
- * - BT_LOGI_AUX(&log_instance, "format string", args, ...)
- * - BT_LOGW_AUX(&log_instance, "format string", args, ...)
- * - BT_LOGE_AUX(&log_instance, "format string", args, ...)
- * - BT_LOGF_AUX(&log_instance, "format string", args, ...)
- *
- * Auxiliary memory logging macros:
- * - BT_LOGT_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...)
- * - BT_LOGD_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...)
- * - BT_LOGI_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...)
- * - BT_LOGW_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...)
- * - BT_LOGE_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...)
- * - BT_LOGF_MEM_AUX(&log_instance, data_ptr, data_sz, "format string", args, ...)
- *
- * Preformatted string logging macros:
- * - BT_LOGT_STR("preformatted string");
- * - BT_LOGD_STR("preformatted string");
- * - BT_LOGI_STR("preformatted string");
- * - BT_LOGW_STR("preformatted string");
- * - BT_LOGE_STR("preformatted string");
- * - BT_LOGF_STR("preformatted string");
- *
- * Explicit log level and tag macros:
- * - BT_LOG_WRITE(level, tag, "format string", args, ...)
- * - BT_LOG_WRITE_MEM(level, tag, data_ptr, data_sz, "format string", args, ...)
- * - BT_LOG_WRITE_AUX(&log_instance, level, tag, "format string", args, ...)
- * - BT_LOG_WRITE_MEM_AUX(&log_instance, level, tag, data_ptr, data_sz,
- * "format string", args, ...)
- *
- * Explicit log level, current log level, and tag:
- * - BT_LOG_WRITE_CUR_LVL(level, cur_level, tag, "format string", args, ...)
- *
- * Format string follows printf() conventions. Both data_ptr and data_sz could
- * be 0. Tag can be 0 as well. Most compilers will verify that type of arguments
- * match format specifiers in format string.
- *
- * Library assuming UTF-8 encoding for all strings (char *), including format
- * string itself.
- */
-#if BT_LOG_SRCLOC_NONE == _BT_LOG_SRCLOC
- #define BT_LOG_WRITE(lvl, tag, ...) \
- do { \
- if (BT_LOG_ON(lvl)) \
- _bt_log_write(lvl, tag, __VA_ARGS__); \
- } _BT_LOG_ONCE
- #define BT_LOG_WRITE_CUR_LVL(lvl, cur_lvl, tag, ...) \
- do { \
- if (BT_LOG_ON_CUR_LVL((lvl), (cur_lvl))) \
- _bt_log_write(lvl, tag, __VA_ARGS__); \
- } _BT_LOG_ONCE
- #define BT_LOG_WRITE_MEM(lvl, tag, d, d_sz, ...) \
- do { \
- if (BT_LOG_ON(lvl)) \
- _bt_log_write_mem(lvl, tag, d, d_sz, __VA_ARGS__); \
- } _BT_LOG_ONCE
- #define BT_LOG_WRITE_AUX(log, lvl, tag, ...) \
- do { \
- if (BT_LOG_ON(lvl)) \
- _bt_log_write_aux(log, lvl, tag, __VA_ARGS__); \
- } _BT_LOG_ONCE
- #define BT_LOG_WRITE_MEM_AUX(log, lvl, tag, d, d_sz, ...) \
- do { \
- if (BT_LOG_ON(lvl)) \
- _bt_log_write_mem_aux(log, lvl, tag, d, d_sz, __VA_ARGS__); \
- } _BT_LOG_ONCE
-#else
- #define BT_LOG_WRITE(lvl, tag, ...) \
- do { \
- if (BT_LOG_ON(lvl)) \
- _bt_log_write_d(_BT_LOG_SRCLOC_FUNCTION, __FILE__, __LINE__, \
- lvl, tag, __VA_ARGS__); \
- } _BT_LOG_ONCE
- #define BT_LOG_WRITE_CUR_LVL(lvl, cur_lvl, tag, ...) \
- do { \
- if (BT_LOG_ON_CUR_LVL((lvl), (cur_lvl))) \
- _bt_log_write_d(_BT_LOG_SRCLOC_FUNCTION, __FILE__, __LINE__, \
- lvl, tag, __VA_ARGS__); \
- } _BT_LOG_ONCE
- #define BT_LOG_WRITE_MEM(lvl, tag, d, d_sz, ...) \
- do { \
- if (BT_LOG_ON(lvl)) \
- _bt_log_write_mem_d(_BT_LOG_SRCLOC_FUNCTION, __FILE__, __LINE__, \
- lvl, tag, d, d_sz, __VA_ARGS__); \
- } _BT_LOG_ONCE
- #define BT_LOG_WRITE_AUX(log, lvl, tag, ...) \
- do { \
- if (BT_LOG_ON(lvl)) \
- _bt_log_write_aux_d(_BT_LOG_SRCLOC_FUNCTION, __FILE__, __LINE__, \
- log, lvl, tag, __VA_ARGS__); \
- } _BT_LOG_ONCE
- #define BT_LOG_WRITE_MEM_AUX(log, lvl, tag, d, d_sz, ...) \
- do { \
- if (BT_LOG_ON(lvl)) \
- _bt_log_write_mem_aux_d(_BT_LOG_SRCLOC_FUNCTION, __FILE__, __LINE__, \
- log, lvl, tag, d, d_sz, __VA_ARGS__); \
- } _BT_LOG_ONCE
-#endif
-
-#define BT_LOG_WRITE_ERRNO_CUR_LVL(lvl, cur_lvl, tag, _msg, _fmt, args...) \
- do { \
- const char *error_str; \
- error_str = g_strerror(errno); \
- BT_LOG_WRITE_CUR_LVL(lvl, cur_lvl, tag, _msg ": %s" _fmt, error_str, ## args); \
- } _BT_LOG_ONCE
-
-#define BT_LOG_WRITE_ERRNO(lvl, tag, _msg, _fmt, args...) \
- do { \
- BT_LOG_WRITE_ERRNO_CUR_LVL(lvl, _BT_LOG_OUTPUT_LEVEL, tag, _msg, _fmt, ## args); \
- } _BT_LOG_ONCE
-
-static _BT_LOG_INLINE void _bt_log_unused(const int dummy, ...) {(void)dummy;}