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.
 
 
 
 

44 lines
1.6 KiB

  1. #pragma once
  2. #include <stdbool.h>
  3. #include "macros.h"
  4. enum log_colorize { LOG_COLORIZE_NEVER, LOG_COLORIZE_ALWAYS, LOG_COLORIZE_AUTO };
  5. enum log_facility { LOG_FACILITY_USER, LOG_FACILITY_DAEMON };
  6. enum log_class { LOG_CLASS_ERROR, LOG_CLASS_WARNING, LOG_CLASS_INFO, LOG_CLASS_DEBUG };
  7. void log_init(enum log_colorize colorize, bool do_syslog,
  8. enum log_facility syslog_facility, enum log_class syslog_level);
  9. void log_deinit(void);
  10. void log_msg(enum log_class log_class, const char *module,
  11. const char *file, int lineno,
  12. const char *fmt, ...) PRINTF(5);
  13. void log_errno(enum log_class log_class, const char *module,
  14. const char *file, int lineno,
  15. const char *fmt, ...) PRINTF(5);
  16. void log_errno_provided(
  17. enum log_class log_class, const char *module,
  18. const char *file, int lineno, int _errno,
  19. const char *fmt, ...) PRINTF(6);
  20. #define LOG_ERR(...) \
  21. log_msg(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, __VA_ARGS__)
  22. #define LOG_ERRNO(...) \
  23. log_errno(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, __VA_ARGS__)
  24. #define LOG_ERRNO_P(_errno, ...) \
  25. log_errno_provided(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, \
  26. _errno, __VA_ARGS__)
  27. #define LOG_WARN(...) \
  28. log_msg(LOG_CLASS_WARNING, LOG_MODULE, __FILE__, __LINE__, __VA_ARGS__)
  29. #define LOG_INFO(...) \
  30. log_msg(LOG_CLASS_INFO, LOG_MODULE, __FILE__, __LINE__, __VA_ARGS__)
  31. #if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG
  32. #define LOG_DBG(...) \
  33. log_msg(LOG_CLASS_DEBUG, LOG_MODULE, __FILE__, __LINE__, __VA_ARGS__)
  34. #else
  35. #define LOG_DBG(...)
  36. #endif