bh_log.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. void
  36. bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...);
  37. #ifdef BH_PLATFORM_NUTTX
  38. #undef LOG_FATAL
  39. #undef LOG_ERROR
  40. #undef LOG_WARNING
  41. #undef LOG_VERBOSE
  42. #undef LOG_DEBUG
  43. #endif
  44. #if BH_DEBUG != 0
  45. #define LOG_FATAL(...) \
  46. bh_log(BH_LOG_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__)
  47. #else
  48. #define LOG_FATAL(...) \
  49. bh_log(BH_LOG_LEVEL_FATAL, __FUNCTION__, __LINE__, __VA_ARGS__)
  50. #endif
  51. #define LOG_ERROR(...) bh_log(BH_LOG_LEVEL_ERROR, NULL, 0, __VA_ARGS__)
  52. #define LOG_WARNING(...) bh_log(BH_LOG_LEVEL_WARNING, NULL, 0, __VA_ARGS__)
  53. #define LOG_VERBOSE(...) bh_log(BH_LOG_LEVEL_VERBOSE, NULL, 0, __VA_ARGS__)
  54. #if BH_DEBUG != 0
  55. #define LOG_DEBUG(...) \
  56. bh_log(BH_LOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
  57. #else
  58. #define LOG_DEBUG(...) (void)0
  59. #endif
  60. void
  61. bh_print_time(const char *prompt);
  62. void
  63. bh_print_proc_mem(const char *prompt);
  64. void
  65. bh_log_proc_mem(const char *function, uint32 line);
  66. #define LOG_PROC_MEM(...) bh_log_proc_mem(__FUNCTION__, __LINE__)
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif /* _BH_LOG_H */