logging.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef CORE_LOGGING_H
  2. #define CORE_LOGGING_H
  3. #include <stdio.h>
  4. #include "opthelpers.h"
  5. enum class LogLevel {
  6. Disable,
  7. Error,
  8. Warning,
  9. Trace
  10. };
  11. extern LogLevel gLogLevel;
  12. extern FILE *gLogFile;
  13. #if !defined(_WIN32) && !defined(__ANDROID__)
  14. #define TRACE(...) do { \
  15. if UNLIKELY(gLogLevel >= LogLevel::Trace) \
  16. fprintf(gLogFile, "[ALSOFT] (II) " __VA_ARGS__); \
  17. } while(0)
  18. #define WARN(...) do { \
  19. if UNLIKELY(gLogLevel >= LogLevel::Warning) \
  20. fprintf(gLogFile, "[ALSOFT] (WW) " __VA_ARGS__); \
  21. } while(0)
  22. #define ERR(...) do { \
  23. if UNLIKELY(gLogLevel >= LogLevel::Error) \
  24. fprintf(gLogFile, "[ALSOFT] (EE) " __VA_ARGS__); \
  25. } while(0)
  26. #else
  27. [[gnu::format(printf,3,4)]] void al_print(LogLevel level, FILE *logfile, const char *fmt, ...);
  28. #define TRACE(...) al_print(LogLevel::Trace, gLogFile, "[ALSOFT] (II) " __VA_ARGS__)
  29. #define WARN(...) al_print(LogLevel::Warning, gLogFile, "[ALSOFT] (WW) " __VA_ARGS__)
  30. #define ERR(...) al_print(LogLevel::Error, gLogFile, "[ALSOFT] (EE) " __VA_ARGS__)
  31. #endif
  32. #endif /* CORE_LOGGING_H */