log.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include <stdio.h>
  3. #include <stdint.h>
  4. #include <stdarg.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #define FURI_LOG_LEVEL_DEFAULT 3
  9. #ifndef FURI_LOG_LEVEL
  10. #define FURI_LOG_LEVEL FURI_LOG_LEVEL_DEFAULT
  11. #endif
  12. #define FURI_LOG_CLR(clr) "\033[0;" clr "m"
  13. #define FURI_LOG_CLR_RESET "\033[0m"
  14. #define FURI_LOG_CLR_BLACK "30"
  15. #define FURI_LOG_CLR_RED "31"
  16. #define FURI_LOG_CLR_GREEN "32"
  17. #define FURI_LOG_CLR_BROWN "33"
  18. #define FURI_LOG_CLR_BLUE "34"
  19. #define FURI_LOG_CLR_PURPLE "35"
  20. #define FURI_LOG_CLR_E FURI_LOG_CLR(FURI_LOG_CLR_RED)
  21. #define FURI_LOG_CLR_W FURI_LOG_CLR(FURI_LOG_CLR_BROWN)
  22. #define FURI_LOG_CLR_I FURI_LOG_CLR(FURI_LOG_CLR_GREEN)
  23. #define FURI_LOG_CLR_D FURI_LOG_CLR(FURI_LOG_CLR_BLUE)
  24. #define FURI_LOG_CLR_V
  25. typedef int (*FuriLogPrint)(const char*, ...);
  26. typedef int (*FuriLogVPrint)(const char*, va_list);
  27. typedef uint32_t (*FuriLogTimestamp)(void);
  28. typedef enum {
  29. FURI_LOG_NONE = 0,
  30. FURI_LOG_ERROR = 1,
  31. FURI_LOG_WARN = 2,
  32. FURI_LOG_INFO = 3,
  33. FURI_LOG_DEBUG = 4,
  34. FURI_LOG_VERBOSE = 5,
  35. } FuriLogLevel;
  36. void furi_log_init();
  37. void furi_log_print(FuriLogLevel level, const char* format, ...);
  38. void furi_log_set_level(FuriLogLevel level);
  39. FuriLogLevel furi_log_get_level();
  40. void furi_log_set_print(FuriLogPrint print, FuriLogVPrint vprint);
  41. void furi_log_set_timestamp(FuriLogTimestamp timestamp);
  42. #define FURI_LOG_FORMAT(log_letter, tag, format) \
  43. FURI_LOG_CLR_##log_letter "[" #log_letter "][" tag "]: " FURI_LOG_CLR_RESET format "\r\n"
  44. #define FURI_LOG_SHOW(tag, format, log_level, log_letter, ...) \
  45. furi_log_print(log_level, FURI_LOG_FORMAT(log_letter, tag, format), ##__VA_ARGS__)
  46. #define FURI_LOG_E(tag, format, ...) FURI_LOG_SHOW(tag, format, FURI_LOG_ERROR, E, ##__VA_ARGS__)
  47. #define FURI_LOG_W(tag, format, ...) FURI_LOG_SHOW(tag, format, FURI_LOG_WARN, W, ##__VA_ARGS__)
  48. #define FURI_LOG_I(tag, format, ...) FURI_LOG_SHOW(tag, format, FURI_LOG_INFO, I, ##__VA_ARGS__)
  49. #define FURI_LOG_D(tag, format, ...) FURI_LOG_SHOW(tag, format, FURI_LOG_DEBUG, D, ##__VA_ARGS__)
  50. #define FURI_LOG_V(tag, format, ...) FURI_LOG_SHOW(tag, format, FURI_LOG_VERBOSE, V, ##__VA_ARGS__)
  51. #ifdef __cplusplus
  52. }
  53. #endif