#ifndef _AL_LOG_H #define _AL_LOG_H // https://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html #include #include AL_IGNORE_WARNING("-Wunused-variable") #ifndef AL_LOG_SECTION static const char *AL_LOG_SECTION_NAME = ""; #else static const char *AL_LOG_SECTION_NAME = AL_LOG_SECTION; #endif AL_IGNORE_WARNING_END #define __LOCATION__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__ #define AL_LOG_MESSAGE_SIZE 256u enum { AL_LOG_INFO = 0, AL_LOG_WARN, AL_LOG_ERROR, AL_LOG_DEBUG, AL_LOG_TRACE }; void al_set_print(s32 (*print_func)(void *, u8, char *), void *userdata); s32 _al_log(u8 level, const char *section, const char *name, const s32 line, const char *func, const char *fmt, ...); s32 _al_logv(u8 level, const char *section, const char *name, const s32 line, const char *func, const char *fmt, va_list args); #define al_log(level, section, fmt, ...) _al_log(level, section, __LOCATION__, fmt, ##__VA_ARGS__) #define al_logv(level, section, fmt, args) _al_logv(level, section, __LOCATION__, fmt, args) #define log_info(fmt, ...) al_log(AL_LOG_INFO, AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__) #define log_warn(fmt, ...) al_log(AL_LOG_WARN, AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__) #define log_error(fmt, ...) al_log(AL_LOG_ERROR, AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__) #if defined AL_DEBUG || defined AL_LOG_ENABLE_TRACE #define log_debug(fmt, ...) al_log(AL_LOG_DEBUG, AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__) #else #define log_debug(fmt, ...) al_log_nop(AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__) #endif #ifdef AL_LOG_ENABLE_TRACE #define log_trace(fmt, ...) al_log(AL_LOG_TRACE, AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__) #else #define log_trace(fmt, ...) al_log_nop(AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__) #endif static inline s32 al_log_nop(const char *section, const char *fmt, ...) { (void)section; (void)fmt; return 0; } #endif // _AL_LOG_H