bh_log.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. /**
  6. * @file bh_log.h
  7. * @date Tue Nov 8 18:19:10 2011
  8. *
  9. * @brief This log system supports wrapping multiple outputs into one
  10. * log message. This is useful for outputting variable-length logs
  11. * without additional memory overhead (the buffer for concatenating
  12. * the message), e.g. exception stack trace, which cannot be printed
  13. * by a single log calling without the help of an additional buffer.
  14. * Avoiding additional memory buffer is useful for resource-constraint
  15. * systems. It can minimize the impact of log system on applications
  16. * and logs can be printed even when no enough memory is available.
  17. * Functions with prefix "_" are private functions. Only macros that
  18. * are not start with "_" are exposed and can be used.
  19. */
  20. #ifndef _BH_LOG_H
  21. #define _BH_LOG_H
  22. #include "bh_platform.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. typedef enum {
  27. BH_LOG_LEVEL_FATAL = 0,
  28. BH_LOG_LEVEL_ERROR = 1,
  29. BH_LOG_LEVEL_WARNING = 2,
  30. BH_LOG_LEVEL_DEBUG = 3,
  31. BH_LOG_LEVEL_VERBOSE = 4
  32. } LogLevel;
  33. void
  34. bh_log_set_verbose_level(uint32 level);
  35. #ifndef BH_LOG
  36. void
  37. bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...);
  38. #else
  39. void
  40. BH_LOG(uint32 log_level, const char *file, int line, const char *fmt, ...);
  41. #define bh_log BH_LOG
  42. #endif
  43. #ifdef BH_PLATFORM_NUTTX
  44. #undef LOG_FATAL
  45. #undef LOG_ERROR
  46. #undef LOG_WARNING
  47. #undef LOG_VERBOSE
  48. #undef LOG_DEBUG
  49. #endif
  50. #if BH_DEBUG != 0
  51. #define LOG_FATAL(...) \
  52. bh_log(BH_LOG_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__)
  53. #else
  54. #define LOG_FATAL(...) \
  55. bh_log(BH_LOG_LEVEL_FATAL, __FUNCTION__, __LINE__, __VA_ARGS__)
  56. #endif
  57. #define LOG_ERROR(...) bh_log(BH_LOG_LEVEL_ERROR, NULL, 0, __VA_ARGS__)
  58. #define LOG_WARNING(...) bh_log(BH_LOG_LEVEL_WARNING, NULL, 0, __VA_ARGS__)
  59. #define LOG_VERBOSE(...) bh_log(BH_LOG_LEVEL_VERBOSE, NULL, 0, __VA_ARGS__)
  60. #if BH_DEBUG != 0
  61. #define LOG_DEBUG(...) \
  62. bh_log(BH_LOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
  63. #else
  64. #define LOG_DEBUG(...) (void)0
  65. #endif
  66. void
  67. bh_print_time(const char *prompt);
  68. void
  69. bh_print_proc_mem(const char *prompt);
  70. void
  71. bh_log_proc_mem(const char *function, uint32 line);
  72. #define LOG_PROC_MEM(...) bh_log_proc_mem(__FUNCTION__, __LINE__)
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif /* _BH_LOG_H */