🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3 KiB

  1. #ifndef LOGGING_H
  2. #define LOGGING_H
  3. #include <stdio.h>
  4. #include "opthelpers.h"
  5. #ifdef __GNUC__
  6. #define DECL_FORMAT(x, y, z) __attribute__((format(x, (y), (z))))
  7. #else
  8. #define DECL_FORMAT(x, y, z)
  9. #endif
  10. extern FILE *gLogFile;
  11. constexpr inline const char *CurrentPrefix() noexcept { return ""; }
  12. #if defined(__GNUC__) && !defined(_WIN32)
  13. #define AL_PRINT(T, MSG, ...) fprintf(gLogFile, "AL lib: %s %s%s: " MSG, T, CurrentPrefix(), __FUNCTION__ , ## __VA_ARGS__)
  14. #else
  15. void al_print(const char *type, const char *prefix, const char *func, const char *fmt, ...) DECL_FORMAT(printf, 4,5);
  16. #define AL_PRINT(T, ...) al_print((T), CurrentPrefix(), __FUNCTION__, __VA_ARGS__)
  17. #endif
  18. #ifdef __ANDROID__
  19. #include <android/log.h>
  20. #define LOG_ANDROID(T, MSG, ...) __android_log_print(T, "openal", "AL lib: %s%s: " MSG, CurrentPrefix(), __FUNCTION__ , ## __VA_ARGS__)
  21. #else
  22. #define LOG_ANDROID(T, MSG, ...) ((void)0)
  23. #endif
  24. enum LogLevel {
  25. NoLog,
  26. LogError,
  27. LogWarning,
  28. LogTrace,
  29. LogRef
  30. };
  31. extern LogLevel gLogLevel;
  32. #define TRACEREF(...) do { \
  33. if(UNLIKELY(gLogLevel >= LogRef)) \
  34. AL_PRINT("(--)", __VA_ARGS__); \
  35. } while(0)
  36. #define TRACE(...) do { \
  37. if(UNLIKELY(gLogLevel >= LogTrace)) \
  38. AL_PRINT("(II)", __VA_ARGS__); \
  39. LOG_ANDROID(ANDROID_LOG_DEBUG, __VA_ARGS__); \
  40. } while(0)
  41. #define WARN(...) do { \
  42. if(UNLIKELY(gLogLevel >= LogWarning)) \
  43. AL_PRINT("(WW)", __VA_ARGS__); \
  44. LOG_ANDROID(ANDROID_LOG_WARN, __VA_ARGS__); \
  45. } while(0)
  46. #define ERR(...) do { \
  47. if(UNLIKELY(gLogLevel >= LogError)) \
  48. AL_PRINT("(EE)", __VA_ARGS__); \
  49. LOG_ANDROID(ANDROID_LOG_ERROR, __VA_ARGS__); \
  50. } while(0)
  51. #endif /* LOGGING_H */