swlog.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. *@file swlog.h
  3. *@brief 调用go语言中提供的日志回调输出日志
  4. *@author niujiuru
  5. *data 2025-01-07
  6. */
  7. #ifndef __SWLOG_H__
  8. #define __SWLOG_H__
  9. // 打印输出级别
  10. typedef enum
  11. {
  12. LEVEL_TRACE = 0, // trace
  13. LEVEL_DEBUG, // debug
  14. LEVEL_INFO, // info
  15. LEVEL_WARN, // warning
  16. LEVEL_ERROR, // error
  17. LEVEL_FATAL, // fatal
  18. } ELogLevel;
  19. // 带有打印级别的打印输出(该函数会自动在行尾加入回车换行符)
  20. void sw_log_writeWithLevel(ELogLevel level, const char *file, int line, const char *format, ...);
  21. // trace日志
  22. #define sw_log_trace(format, ...) \
  23. sw_log_writeWithLevel(LEVEL_TRACE, __FILE__, __LINE__, (format), ##__VA_ARGS__)
  24. // debug日志
  25. #define sw_log_debug(format, ...) \
  26. sw_log_writeWithLevel(LEVEL_DEBUG, __FILE__, __LINE__, (format), ##__VA_ARGS__)
  27. // info日志
  28. #define sw_log_info(format, ...) \
  29. sw_log_writeWithLevel(LEVEL_INFO, __FILE__, __LINE__, (format), ##__VA_ARGS__)
  30. // warning日志
  31. #define sw_log_warn(format, ...) \
  32. sw_log_writeWithLevel(LEVEL_WARN, __FILE__, __LINE__, (format), ##__VA_ARGS__)
  33. // error日志
  34. #define sw_log_error(format, ...) \
  35. sw_log_writeWithLevel(LEVEL_ERROR, __FILE__, __LINE__, (format), ##__VA_ARGS__)
  36. // fatal日志
  37. #define sw_log_fatal(format, ...) \
  38. sw_log_writeWithLevel(LEVEL_FATAL, __FILE__, __LINE__, (format), ##__VA_ARGS__)
  39. #endif /* __SWLOG_H__ */