log.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * @file log.h
  3. * Furi Logging system
  4. */
  5. #pragma once
  6. #include <stdio.h>
  7. #include <stdint.h>
  8. #include <stdarg.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. typedef enum {
  13. FuriLogLevelDefault = 0,
  14. FuriLogLevelNone = 1,
  15. FuriLogLevelError = 2,
  16. FuriLogLevelWarn = 3,
  17. FuriLogLevelInfo = 4,
  18. FuriLogLevelDebug = 5,
  19. FuriLogLevelTrace = 6,
  20. } FuriLogLevel;
  21. #define FURI_LOG_CLR(clr) "\033[0;" clr "m"
  22. #define FURI_LOG_CLR_RESET "\033[0m"
  23. #define FURI_LOG_CLR_BLACK "30"
  24. #define FURI_LOG_CLR_RED "31"
  25. #define FURI_LOG_CLR_GREEN "32"
  26. #define FURI_LOG_CLR_BROWN "33"
  27. #define FURI_LOG_CLR_BLUE "34"
  28. #define FURI_LOG_CLR_PURPLE "35"
  29. #define FURI_LOG_CLR_E FURI_LOG_CLR(FURI_LOG_CLR_RED)
  30. #define FURI_LOG_CLR_W FURI_LOG_CLR(FURI_LOG_CLR_BROWN)
  31. #define FURI_LOG_CLR_I FURI_LOG_CLR(FURI_LOG_CLR_GREEN)
  32. #define FURI_LOG_CLR_D FURI_LOG_CLR(FURI_LOG_CLR_BLUE)
  33. #define FURI_LOG_CLR_T FURI_LOG_CLR(FURI_LOG_CLR_PURPLE)
  34. typedef void (*FuriLogPuts)(const char* data);
  35. typedef uint32_t (*FuriLogTimestamp)(void);
  36. /** Initialize logging */
  37. void furi_log_init();
  38. /** Print log record
  39. *
  40. * @param level
  41. * @param tag
  42. * @param format
  43. * @param ...
  44. */
  45. void furi_log_print_format(FuriLogLevel level, const char* tag, const char* format, ...)
  46. _ATTRIBUTE((__format__(__printf__, 3, 4)));
  47. /** Set log level
  48. *
  49. * @param[in] level The level
  50. */
  51. void furi_log_set_level(FuriLogLevel level);
  52. /** Get log level
  53. *
  54. * @return The furi log level.
  55. */
  56. FuriLogLevel furi_log_get_level();
  57. /** Set log output callback
  58. *
  59. * @param[in] puts The puts callback
  60. */
  61. void furi_log_set_puts(FuriLogPuts puts);
  62. /** Set timestamp callback
  63. *
  64. * @param[in] timestamp The timestamp callback
  65. */
  66. void furi_log_set_timestamp(FuriLogTimestamp timestamp);
  67. /** Log methods
  68. *
  69. * @param tag The application tag
  70. * @param format The format
  71. * @param ... VA Args
  72. */
  73. #define FURI_LOG_E(tag, format, ...) \
  74. furi_log_print_format(FuriLogLevelError, tag, format, ##__VA_ARGS__)
  75. #define FURI_LOG_W(tag, format, ...) \
  76. furi_log_print_format(FuriLogLevelWarn, tag, format, ##__VA_ARGS__)
  77. #define FURI_LOG_I(tag, format, ...) \
  78. furi_log_print_format(FuriLogLevelInfo, tag, format, ##__VA_ARGS__)
  79. #define FURI_LOG_D(tag, format, ...) \
  80. furi_log_print_format(FuriLogLevelDebug, tag, format, ##__VA_ARGS__)
  81. #define FURI_LOG_T(tag, format, ...) \
  82. furi_log_print_format(FuriLogLevelTrace, tag, format, ##__VA_ARGS__)
  83. #ifdef __cplusplus
  84. }
  85. #endif