tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

cubeb_log.h (2665B)


      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 #if defined(__FILE_NAME__)
     20 #define __FILENAME__ __FILE_NAME__
     21 #else
     22 #define __FILENAME__                                                           \
     23  (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1     \
     24                                    : __FILE__)
     25 #endif
     26 #else
     27 #define PRINTF_FORMAT(fmt, args)
     28 #include <string.h>
     29 #define __FILENAME__                                                           \
     30  (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
     31 #endif
     32 
     33 void
     34 cubeb_log_set(cubeb_log_level log_level, cubeb_log_callback log_callback);
     35 cubeb_log_level
     36 cubeb_log_get_level(void);
     37 cubeb_log_callback
     38 cubeb_log_get_callback(void);
     39 void
     40 cubeb_log_internal_no_format(const char * msg);
     41 void
     42 cubeb_log_internal(const char * filename, uint32_t line, const char * fmt, ...)
     43    PRINTF_FORMAT(3, 4);
     44 void
     45 cubeb_async_log(const char * fmt, ...) PRINTF_FORMAT(1, 2);
     46 void
     47 cubeb_async_log_reset_threads(void);
     48 
     49 #ifdef __cplusplus
     50 }
     51 #endif
     52 
     53 #define LOGV(msg, ...) LOG_INTERNAL(CUBEB_LOG_VERBOSE, msg, ##__VA_ARGS__)
     54 #define LOG(msg, ...) LOG_INTERNAL(CUBEB_LOG_NORMAL, msg, ##__VA_ARGS__)
     55 
     56 #define LOG_INTERNAL(level, fmt, ...)                                          \
     57  do {                                                                         \
     58    if (cubeb_log_get_level() >= level && cubeb_log_get_callback()) {          \
     59      cubeb_log_internal(__FILENAME__, __LINE__, fmt, ##__VA_ARGS__);          \
     60    }                                                                          \
     61  } while (0)
     62 
     63 #define ALOG_INTERNAL(level, fmt, ...)                                         \
     64  do {                                                                         \
     65    if (cubeb_log_get_level() >= level && cubeb_log_get_callback()) {          \
     66      cubeb_async_log(fmt, ##__VA_ARGS__);                                     \
     67    }                                                                          \
     68  } while (0)
     69 
     70 /* Asynchronous logging macros to log in real-time callbacks. */
     71 /* Should not be used on android due to the use of global/static variables. */
     72 #define ALOGV(msg, ...) ALOG_INTERNAL(CUBEB_LOG_VERBOSE, msg, ##__VA_ARGS__)
     73 #define ALOG(msg, ...) ALOG_INTERNAL(CUBEB_LOG_NORMAL, msg, ##__VA_ARGS__)
     74 
     75 #endif // CUBEB_LOG