log.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 void (*FuriLogPuts)(const char* data);
  26. typedef uint32_t (*FuriLogTimestamp)(void);
  27. typedef enum {
  28. FURI_LOG_NONE = 0,
  29. FURI_LOG_ERROR = 1,
  30. FURI_LOG_WARN = 2,
  31. FURI_LOG_INFO = 3,
  32. FURI_LOG_DEBUG = 4,
  33. FURI_LOG_VERBOSE = 5,
  34. } FuriLogLevel;
  35. void furi_log_init();
  36. void furi_log_print(FuriLogLevel level, const char* format, ...);
  37. void furi_log_set_level(FuriLogLevel level);
  38. FuriLogLevel furi_log_get_level();
  39. void furi_log_set_puts(FuriLogPuts puts);
  40. void furi_log_set_timestamp(FuriLogTimestamp timestamp);
  41. #define FURI_LOG_FORMAT(log_letter, tag, format) \
  42. FURI_LOG_CLR_##log_letter "[" #log_letter "][" tag "]: " FURI_LOG_CLR_RESET format "\r\n"
  43. #define FURI_LOG_SHOW(tag, format, log_level, log_letter, ...) \
  44. furi_log_print(log_level, FURI_LOG_FORMAT(log_letter, tag, format), ##__VA_ARGS__)
  45. #define FURI_LOG_E(tag, format, ...) FURI_LOG_SHOW(tag, format, FURI_LOG_ERROR, E, ##__VA_ARGS__)
  46. #define FURI_LOG_W(tag, format, ...) FURI_LOG_SHOW(tag, format, FURI_LOG_WARN, W, ##__VA_ARGS__)
  47. #define FURI_LOG_I(tag, format, ...) FURI_LOG_SHOW(tag, format, FURI_LOG_INFO, I, ##__VA_ARGS__)
  48. #define FURI_LOG_D(tag, format, ...) FURI_LOG_SHOW(tag, format, FURI_LOG_DEBUG, D, ##__VA_ARGS__)
  49. #define FURI_LOG_V(tag, format, ...) FURI_LOG_SHOW(tag, format, FURI_LOG_VERBOSE, V, ##__VA_ARGS__)
  50. #ifdef __cplusplus
  51. }
  52. #endif