1 #ifndef __CUTILS_LOG_H__ 2 #define __CUTILS_LOG_H__ 3 4 #ifndef LOG_TAG 5 #define LOG_TAG nullptr 6 #endif 7 8 enum { 9 ANDROID_LOG_UNKNOWN = 0, 10 ANDROID_LOG_DEFAULT, 11 ANDROID_LOG_VERBOSE, 12 ANDROID_LOG_DEBUG, 13 ANDROID_LOG_INFO, 14 ANDROID_LOG_WARN, 15 ANDROID_LOG_ERROR, 16 ANDROID_LOG_FATAL, 17 ANDROID_LOG_SILENT, 18 }; 19 20 #define android_printLog(prio, tag, format, ...) \ 21 __android_log_print(prio, tag, __FILE__, __LINE__, "[prio %d] " format, prio, ##__VA_ARGS__) 22 23 #define LOG_PRI(priority, tag, ...) android_printLog(priority, tag, __VA_ARGS__) 24 #define ALOG(priority, tag, ...) LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__) 25 26 #define __android_second(dummy, second, ...) second 27 #define __android_rest(first, ...) , ##__VA_ARGS__ 28 29 #define android_printAssert(condition, tag, format, ...) \ 30 __android_log_assert(condition, tag, __FILE__, __LINE__, "assert: condition: %s " format, \ 31 condition, ##__VA_ARGS__) 32 33 #define LOG_ALWAYS_FATAL_IF(condition, ...) \ 34 ((condition) \ 35 ? ((void)android_printAssert(#condition, LOG_TAG, ##__VA_ARGS__)) \ 36 : (void)0) 37 38 #define LOG_ALWAYS_FATAL(...) \ 39 (((void)android_printAssert(NULL, LOG_TAG, ##__VA_ARGS__))) 40 41 #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) 42 #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) 43 #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) 44 #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) 45 #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) 46 47 #define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ##__VA_ARGS__) 48 49 #define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__) 50 51 #define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ##__VA_ARGS__) 52 53 extern "C" { 54 55 int __android_log_print(int priority, const char* tag, const char* file, int line, 56 const char* format, ...); 57 58 [[noreturn]] void __android_log_assert(const char* condition, const char* tag, const char* file, 59 int line, const char* format, ...); 60 } 61 62 #endif 63