streamline_annotate_logging.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Copyright (C) 2021 by Arm Limited. All rights reserved. */
  2. #ifndef STREAMLINE_ANNOTATE_LOGGING_H
  3. #define STREAMLINE_ANNOTATE_LOGGING_H
  4. //Mapped to android log levels - android_LogPriority
  5. enum log_levels {
  6. LOG_UNKNOWN = 0,
  7. LOG_DEFAULT,
  8. LOG_VERBOSE,
  9. LOG_DEBUG,
  10. LOG_INFO,
  11. LOG_WARN,
  12. LOG_ERROR,
  13. LOG_FATAL,
  14. LOG_SILENT
  15. };
  16. /* ANDROID IMPLEMENTATION */
  17. #if defined(ANDROID) || defined(__ANDROID__)
  18. #include <android/log.h>
  19. #define LOG_TAG "AnnotationLog"
  20. #define LOGGING(LOG_LEVEL, fmt, ...) \
  21. __android_log_print(LOG_LEVEL, LOG_TAG, "%s/%s:%d " fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);
  22. /* LINUX IMPLEMENTATION */
  23. #elif defined(linux) || defined(__linux) || defined(__linux__)
  24. // clang-format off
  25. char *log_levels[] = { "UNKNOWN",
  26. "DEFAULT",
  27. "VERBOSE",
  28. "DEBUG",
  29. "INFO",
  30. "WARN",
  31. "ERROR",
  32. "FATAL",
  33. "SILENT"};
  34. // clang-format on
  35. #define LOGGING(LOG_LEVEL, fmt, ...) \
  36. printf("%s/%s:%d [%s] " fmt " \n", __FILE__, __func__, __LINE__, log_levels[LOG_LEVEL], ##__VA_ARGS__);
  37. #endif
  38. //Use to do logging, if not needed un-define this variable
  39. #define ENABLE_LOG
  40. #ifdef ENABLE_LOG
  41. #define LOG(LOG_LEVEL, fmt, ...) LOGGING(LOG_LEVEL, fmt, ##__VA_ARGS__)
  42. #else
  43. #define LOG(LOG_LEVEL, fmt, ...) // nothing
  44. #endif
  45. #endif /* STREAMLINE_ANNOTATE_LOGGING_H */