aos_log.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef LIBAOS_LOG_H
  2. #define LIBAOS_LOG_H
  3. #include "aos_define.h"
  4. AOS_CPP_START
  5. typedef void (*aos_log_print_pt)(const char *message, int len);
  6. typedef void (*aos_log_format_pt)(int level,
  7. const char *file,
  8. int line,
  9. const char *function,
  10. const char *fmt, ...)
  11. __attribute__ ((__format__ (__printf__, 5, 6)));
  12. void aos_log_set_print(aos_log_print_pt p);
  13. void aos_log_set_format(aos_log_format_pt p);
  14. typedef enum {
  15. AOS_LOG_OFF = 1,
  16. AOS_LOG_FATAL,
  17. AOS_LOG_ERROR,
  18. AOS_LOG_WARN,
  19. AOS_LOG_INFO,
  20. AOS_LOG_DEBUG,
  21. AOS_LOG_TRACE,
  22. AOS_LOG_ALL
  23. } aos_log_level_e;
  24. #ifdef WIN32
  25. #define aos_fatal_log(format, ...) if(aos_log_level>=AOS_LOG_FATAL) \
  26. aos_log_format(AOS_LOG_FATAL, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
  27. #define aos_error_log(format, ...) if(aos_log_level>=AOS_LOG_ERROR) \
  28. aos_log_format(AOS_LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
  29. #define aos_warn_log(format, ...) if(aos_log_level>=AOS_LOG_WARN) \
  30. aos_log_format(AOS_LOG_WARN, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
  31. #define aos_info_log(format, ...) if(aos_log_level>=AOS_LOG_INFO) \
  32. aos_log_format(AOS_LOG_INFO, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
  33. #define aos_debug_log(format, ...) if(aos_log_level>=AOS_LOG_DEBUG) \
  34. aos_log_format(AOS_LOG_DEBUG, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
  35. #define aos_trace_log(format, ...) if(aos_log_level>=AOS_LOG_TRACE) \
  36. aos_log_format(AOS_LOG_TRACE, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
  37. #else
  38. #define aos_fatal_log(format, args...) if(aos_log_level>=AOS_LOG_FATAL) \
  39. aos_log_format(AOS_LOG_FATAL, __FILE__, __LINE__, __FUNCTION__, format, ## args)
  40. #define aos_error_log(format, args...) if(aos_log_level>=AOS_LOG_ERROR) \
  41. aos_log_format(AOS_LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, format, ## args)
  42. #define aos_warn_log(format, args...) if(aos_log_level>=AOS_LOG_WARN) \
  43. aos_log_format(AOS_LOG_WARN, __FILE__, __LINE__, __FUNCTION__, format, ## args)
  44. #define aos_info_log(format, args...) if(aos_log_level>=AOS_LOG_INFO) \
  45. aos_log_format(AOS_LOG_INFO, __FILE__, __LINE__, __FUNCTION__, format, ## args)
  46. #define aos_debug_log(format, args...) if(aos_log_level>=AOS_LOG_DEBUG) \
  47. aos_log_format(AOS_LOG_DEBUG, __FILE__, __LINE__, __FUNCTION__, format, ## args)
  48. #define aos_trace_log(format, args...) if(aos_log_level>=AOS_LOG_TRACE) \
  49. aos_log_format(AOS_LOG_TRACE, __FILE__, __LINE__, __FUNCTION__, format, ## args)
  50. #endif
  51. void aos_log_set_level(aos_log_level_e level);
  52. void aos_log_set_output(apr_file_t *output);
  53. void aos_log_print_default(const char *message, int len);
  54. void aos_log_format_default(int level,
  55. const char *file,
  56. int line,
  57. const char *function,
  58. const char *fmt, ...)
  59. __attribute__ ((__format__ (__printf__, 5, 6)));
  60. extern aos_log_level_e aos_log_level;
  61. extern aos_log_format_pt aos_log_format;
  62. extern aos_log_format_pt aos_log_format;
  63. AOS_CPP_END
  64. #endif