log.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /** Set log level
  47. *
  48. * @param[in] level The level
  49. */
  50. void furi_log_set_level(FuriLogLevel level);
  51. /** Get log level
  52. *
  53. * @return The furi log level.
  54. */
  55. FuriLogLevel furi_log_get_level();
  56. /** Set log output callback
  57. *
  58. * @param[in] puts The puts callback
  59. */
  60. void furi_log_set_puts(FuriLogPuts puts);
  61. /** Set timestamp callback
  62. *
  63. * @param[in] timestamp The timestamp callback
  64. */
  65. void furi_log_set_timestamp(FuriLogTimestamp timestamp);
  66. /** Log methods
  67. *
  68. * @param tag The application tag
  69. * @param format The format
  70. * @param ... VA Args
  71. */
  72. #define FURI_LOG_E(tag, format, ...) \
  73. furi_log_print_format(FuriLogLevelError, tag, format, ##__VA_ARGS__)
  74. #define FURI_LOG_W(tag, format, ...) \
  75. furi_log_print_format(FuriLogLevelWarn, tag, format, ##__VA_ARGS__)
  76. #define FURI_LOG_I(tag, format, ...) \
  77. furi_log_print_format(FuriLogLevelInfo, tag, format, ##__VA_ARGS__)
  78. #define FURI_LOG_D(tag, format, ...) \
  79. furi_log_print_format(FuriLogLevelDebug, tag, format, ##__VA_ARGS__)
  80. #define FURI_LOG_T(tag, format, ...) \
  81. furi_log_print_format(FuriLogLevelTrace, tag, format, ##__VA_ARGS__)
  82. #ifdef __cplusplus
  83. }
  84. #endif