logging.h 929 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef CORE_LOGGING_H
  2. #define CORE_LOGGING_H
  3. #include <cstdio>
  4. #include "fmt/core.h"
  5. #include "opthelpers.h"
  6. enum class LogLevel {
  7. Disable,
  8. Error,
  9. Warning,
  10. Trace
  11. };
  12. DECL_HIDDEN extern LogLevel gLogLevel;
  13. DECL_HIDDEN extern FILE *gLogFile;
  14. using LogCallbackFunc = void(*)(void *userptr, char level, const char *message, int length) noexcept;
  15. void al_set_log_callback(LogCallbackFunc callback, void *userptr);
  16. void al_print_impl(LogLevel level, const fmt::string_view fmt, fmt::format_args args);
  17. template<typename ...Args>
  18. void al_print(LogLevel level, fmt::format_string<Args...> fmt, Args&& ...args) noexcept
  19. try {
  20. al_print_impl(level, fmt, fmt::make_format_args(args...));
  21. } catch(...) { }
  22. #define TRACE(...) al_print(LogLevel::Trace, __VA_ARGS__)
  23. #define WARN(...) al_print(LogLevel::Warning, __VA_ARGS__)
  24. #define ERR(...) al_print(LogLevel::Error, __VA_ARGS__)
  25. #endif /* CORE_LOGGING_H */