bh_log.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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(...) bh_log(BH_LOG_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__)
  46. #else
  47. #define LOG_FATAL(...) bh_log(BH_LOG_LEVEL_FATAL, __FUNCTION__, __LINE__, __VA_ARGS__)
  48. #endif
  49. #define LOG_ERROR(...) bh_log(BH_LOG_LEVEL_ERROR, NULL, 0, __VA_ARGS__)
  50. #define LOG_WARNING(...) bh_log(BH_LOG_LEVEL_WARNING, NULL, 0, __VA_ARGS__)
  51. #define LOG_VERBOSE(...) bh_log(BH_LOG_LEVEL_VERBOSE, NULL, 0, __VA_ARGS__)
  52. #if BH_DEBUG != 0
  53. #define LOG_DEBUG(...) bh_log(BH_LOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
  54. #else
  55. #define LOG_DEBUG(...) (void)0
  56. #endif
  57. void
  58. bh_print_time(const char *prompt);
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif /* _BH_LOG_H */