bh_log.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #if BH_DEBUG == 1
  38. #define LOG_FATAL(...) bh_log(BH_LOG_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__)
  39. #else
  40. #define LOG_FATAL(...) bh_log(BH_LOG_LEVEL_FATAL, __FUNCTION__, __LINE__, __VA_ARGS__)
  41. #endif
  42. #define LOG_ERROR(...) bh_log(BH_LOG_LEVEL_ERROR, NULL, 0, __VA_ARGS__)
  43. #define LOG_WARNING(...) bh_log(BH_LOG_LEVEL_WARNING, NULL, 0, __VA_ARGS__)
  44. #define LOG_VERBOSE(...) bh_log(BH_LOG_LEVEL_VERBOSE, NULL, 0, __VA_ARGS__)
  45. #if BH_DEBUG == 1
  46. #define LOG_DEBUG(...) bh_log(BH_LOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
  47. #else
  48. #define LOG_DEBUG(...) /* do nothing */
  49. #endif
  50. void
  51. bh_print_time(const char *prompt);
  52. #ifdef __cplusplus
  53. }
  54. #endif
  55. #endif /* _BH_LOG_H */