log.h 1004 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef LOG_H_
  2. #define LOG_H_
  3. #include "args.h"
  4. enum {
  5. LOGLEVEL_ERROR,
  6. LOGLEVEL_INFO,
  7. LOGLEVEL_DEBUG,
  8. LOGLEVEL_VERBOSE,
  9. };
  10. #define loglevel_is_error() (cmdargs.loglevel >= LOGLEVEL_ERROR)
  11. #define loglevel_is_info() (cmdargs.loglevel >= LOGLEVEL_INFO)
  12. #define loglevel_is_debug() (cmdargs.loglevel >= LOGLEVEL_DEBUG)
  13. #define loglevel_is_verbose() (cmdargs.loglevel >= LOGLEVEL_VERBOSE)
  14. void loginfo(const char *fmt, ...);
  15. void logerr(const char *fmt, ...);
  16. void _logdebug(const char *fmt, ...);
  17. #define logdebug(...) do { \
  18. if (loglevel_is_debug()) \
  19. _logdebug(__VA_ARGS__); \
  20. } while (0)
  21. #define logverbose(...) do { \
  22. if (loglevel_is_verbose()) \
  23. _logdebug(__VA_ARGS__); \
  24. } while (0)
  25. #define warn_on(cond) do { \
  26. int _warn_on_condition = !!(cond); \
  27. if (_warn_on_condition) \
  28. logerr("Warning: " __FILE__ ":" \
  29. stringify(__LINE__) " (" \
  30. stringify(cond) ") failed\n"); \
  31. } while (0)
  32. void log_initialize(void);
  33. void log_exit(void);
  34. #endif /* LOG_H_ */