logging.h 734 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef CORE_LOGGING_H
  2. #define CORE_LOGGING_H
  3. #include <cstdio>
  4. enum class LogLevel {
  5. Disable,
  6. Error,
  7. Warning,
  8. Trace
  9. };
  10. extern LogLevel gLogLevel;
  11. extern FILE *gLogFile;
  12. using LogCallbackFunc = void(*)(void *userptr, char level, const char *message, int length) noexcept;
  13. void al_set_log_callback(LogCallbackFunc callback, void *userptr);
  14. #ifdef __MINGW32__
  15. [[gnu::format(__MINGW_PRINTF_FORMAT,2,3)]]
  16. #else
  17. [[gnu::format(printf,2,3)]]
  18. #endif
  19. void al_print(LogLevel level, const char *fmt, ...) noexcept;
  20. #define TRACE(...) al_print(LogLevel::Trace, __VA_ARGS__)
  21. #define WARN(...) al_print(LogLevel::Warning, __VA_ARGS__)
  22. #define ERR(...) al_print(LogLevel::Error, __VA_ARGS__)
  23. #endif /* CORE_LOGGING_H */