1 /*
2  * Copyright © 2016 Mozilla Foundation
3  *
4  * This program is made available under an ISC-style license.  See the
5  * accompanying file LICENSE for details.
6  */
7 
8 #ifndef CUBEB_LOG
9 #define CUBEB_LOG
10 
11 #include "cubeb/cubeb.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #if defined(__GNUC__) || defined(__clang__)
18 #define PRINTF_FORMAT(fmt, args) __attribute__((format(printf, fmt, args)))
19 #else
20 #define PRINTF_FORMAT(fmt, args)
21 #endif
22 
23 extern cubeb_log_level g_cubeb_log_level;
24 extern cubeb_log_callback g_cubeb_log_callback PRINTF_FORMAT(1, 2);
25 void cubeb_async_log(const char * fmt, ...);
26 void cubeb_async_log_reset_threads();
27 
28 #ifdef __cplusplus
29 }
30 #endif
31 
32 #define LOGV(msg, ...) LOG_INTERNAL(CUBEB_LOG_VERBOSE, msg, ##__VA_ARGS__)
33 #define LOG(msg, ...) LOG_INTERNAL(CUBEB_LOG_NORMAL, msg, ##__VA_ARGS__)
34 
35 #define LOG_INTERNAL(level, fmt, ...) do {                                   \
36     if (g_cubeb_log_callback && level <= g_cubeb_log_level) {                            \
37       g_cubeb_log_callback("%s:%d: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
38     }                                                                        \
39   } while(0)
40 
41 /* Asynchronous verbose logging, to log in real-time callbacks. */
42 #define ALOGV(fmt, ...)                   \
43 do {                                      \
44   cubeb_async_log(fmt, ##__VA_ARGS__);    \
45 } while(0)
46 
47 #endif // CUBEB_LOG
48