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.

43 lines
1.0KB

  1. #pragma once
  2. /** Example usage:
  3. DEBUG("error: %d", errno);
  4. will print something like
  5. [0.123 debug myfile.cpp:45] error: 67
  6. */
  7. #define DEBUG(format, ...) logger::log(rack::logger::DEBUG_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__)
  8. #define INFO(format, ...) logger::log(rack::logger::INFO_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__)
  9. #define WARN(format, ...) logger::log(rack::logger::WARN_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__)
  10. #define FATAL(format, ...) logger::log(rack::logger::FATAL_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__)
  11. namespace rack {
  12. /** Logs messages to a file or the console with decoration
  13. */
  14. namespace logger {
  15. enum Level {
  16. DEBUG_LEVEL,
  17. INFO_LEVEL,
  18. WARN_LEVEL,
  19. FATAL_LEVEL
  20. };
  21. void init();
  22. void destroy();
  23. /** Do not use this function directly. Use the macros above.
  24. Thread-safe, meaning messages cannot overlap each other in the log.
  25. */
  26. void log(Level level, const char *filename, int line, const char *format, ...);
  27. } // namespace logger
  28. } // namespace rack