| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright © 2016 Mozilla Foundation | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is made available under an ISC-style license.  See the | 
					
						
							|  |  |  |  * accompanying file LICENSE for details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef CUBEB_LOG
 | 
					
						
							|  |  |  | #define CUBEB_LOG
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "cubeb/cubeb.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined(__GNUC__) || defined(__clang__)
 | 
					
						
							|  |  |  | #define PRINTF_FORMAT(fmt, args) __attribute__((format(printf, fmt, args)))
 | 
					
						
							| 
									
										
										
										
											2020-10-24 11:05:37 +00:00
										 |  |  | #if defined(__FILE_NAME__)
 | 
					
						
							|  |  |  | #define __FILENAME__ __FILE_NAME__
 | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | #define __FILENAME__                                                           \
 | 
					
						
							|  |  |  |   (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1     \ | 
					
						
							|  |  |  |                                     : __FILE__) | 
					
						
							| 
									
										
										
										
											2020-10-24 11:05:37 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | #define PRINTF_FORMAT(fmt, args)
 | 
					
						
							| 
									
										
										
										
											2020-10-24 11:05:37 +00:00
										 |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | #define __FILENAME__                                                           \
 | 
					
						
							|  |  |  |   (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern cubeb_log_level g_cubeb_log_level; | 
					
						
							|  |  |  | extern cubeb_log_callback g_cubeb_log_callback PRINTF_FORMAT(1, 2); | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | void | 
					
						
							|  |  |  | cubeb_async_log(const char * fmt, ...); | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | cubeb_async_log_reset_threads(void); | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define LOGV(msg, ...) LOG_INTERNAL(CUBEB_LOG_VERBOSE, msg, ##__VA_ARGS__)
 | 
					
						
							|  |  |  | #define LOG(msg, ...) LOG_INTERNAL(CUBEB_LOG_NORMAL, msg, ##__VA_ARGS__)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | #define LOG_INTERNAL_NO_FORMAT(level, fmt, ...)                                \
 | 
					
						
							|  |  |  |   do {                                                                         \ | 
					
						
							|  |  |  |     if (g_cubeb_log_callback && level <= g_cubeb_log_level) {                  \ | 
					
						
							|  |  |  |       g_cubeb_log_callback(fmt, __VA_ARGS__);                                  \ | 
					
						
							|  |  |  |     }                                                                          \ | 
					
						
							|  |  |  |   } while (0) | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | #define LOG_INTERNAL(level, fmt, ...)                                          \
 | 
					
						
							|  |  |  |   do {                                                                         \ | 
					
						
							|  |  |  |     if (g_cubeb_log_callback && level <= g_cubeb_log_level) {                  \ | 
					
						
							|  |  |  |       g_cubeb_log_callback("%s:%d: " fmt "\n", __FILENAME__, __LINE__,         \ | 
					
						
							|  |  |  |                            ##__VA_ARGS__);                                     \
 | 
					
						
							|  |  |  |     }                                                                          \ | 
					
						
							|  |  |  |   } while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define ALOG_INTERNAL(level, fmt, ...)                                         \
 | 
					
						
							|  |  |  |   do {                                                                         \ | 
					
						
							|  |  |  |     if (level <= g_cubeb_log_level) {                                          \ | 
					
						
							|  |  |  |       cubeb_async_log(fmt, ##__VA_ARGS__);                                     \ | 
					
						
							|  |  |  |     }                                                                          \ | 
					
						
							|  |  |  |   } while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Asynchronous logging macros to log in real-time callbacks. */ | 
					
						
							| 
									
										
										
										
											2020-12-07 04:28:41 +00:00
										 |  |  | /* Should not be used on android due to the use of global/static variables. */ | 
					
						
							| 
									
										
										
										
											2022-08-05 07:28:17 +00:00
										 |  |  | #define ALOGV(msg, ...) ALOG_INTERNAL(CUBEB_LOG_VERBOSE, msg, ##__VA_ARGS__)
 | 
					
						
							|  |  |  | #define ALOG(msg, ...) ALOG_INTERNAL(CUBEB_LOG_NORMAL, msg, ##__VA_ARGS__)
 | 
					
						
							| 
									
										
										
										
											2020-01-10 04:59:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif // CUBEB_LOG
 |