NvLogging.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of NVIDIA CORPORATION nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  24. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. /**
  29. * @file
  30. * <b>NVIDIA Multimedia API: Logging API</b>
  31. *
  32. * @brief Description: This file defines macros for logging messages.
  33. */
  34. #ifndef __NV_LOGGING_H_
  35. #define __NV_LOGGING_H_
  36. #include <iostream>
  37. #include <sstream>
  38. /**
  39. *
  40. * @defgroup l4t_mm_nvlogging_group Logging API
  41. *
  42. * This file defines macros that provide message logging
  43. * functionality.
  44. *
  45. * @ingroup aa_framework_api_group
  46. * @{
  47. */
  48. /**
  49. * Specifies the log level for Information messages.
  50. */
  51. #define LOG_LEVEL_INFO 0
  52. /**
  53. * Specifies the log level for Error messages.
  54. */
  55. #define LOG_LEVEL_ERROR 1
  56. /**
  57. * Specifies the log level for Warning messages.
  58. */
  59. #define LOG_LEVEL_WARN 2
  60. /**
  61. * Specifies the log level for Debug messages.
  62. */
  63. #define LOG_LEVEL_DEBUG 3
  64. /**
  65. * Holds the current log level at runtime by assignment of one of the
  66. * @c LOG_LEVEL_* values.
  67. */
  68. extern int log_level;
  69. /**
  70. * Specifies the default log level.
  71. */
  72. #define DEFAULT_LOG_LEVEL LOG_LEVEL_ERROR
  73. /**
  74. * @cond
  75. */
  76. #define stringify(s) #s
  77. #define xstringify(s) stringify(s)
  78. #define __LINE_NUM_STR__ xstringify(__LINE__)
  79. extern const char *log_level_name[];
  80. /**
  81. * @endcond
  82. */
  83. /**
  84. *
  85. * Prints log messages.
  86. *
  87. * Prints a log message only if the current log_level is greater
  88. * than or equal to the level of the message.
  89. *
  90. * Messages are in the following form:
  91. * [LEVEL] (FILE: LINE_NUM) Message
  92. *
  93. * @param[in] level The Log level of the message.
  94. * @param[in] str1 The NULL-terminated char array to print.
  95. */
  96. #define PRINT_MSG(level, str1) if(level <= log_level) { \
  97. std::ostringstream ostr; \
  98. ostr << "[" << log_level_name[level] << "] (" << \
  99. __FILE__ << ":" __LINE_NUM_STR__ ") " << \
  100. str1 << std::endl; \
  101. std::cerr << ostr.str(); \
  102. }
  103. /**
  104. * Prints a log message of level LOG_LEVEL_INFO.
  105. */
  106. #define INFO_MSG(str) PRINT_MSG(LOG_LEVEL_INFO, str)
  107. /**
  108. * Prints a component-specific log message of level LOG_LEVEL_INFO.
  109. * This is used by the components internally and should not be used by
  110. * the application.
  111. *
  112. * Messages are in the following form:
  113. * [LEVEL] (FILE: LINE_NUM) <comp_name> <message_content>
  114. */
  115. #define COMP_INFO_MSG(str) INFO_MSG("<" << comp_name << "> " << str)
  116. /**
  117. * Prints a category-specific (Component type) system error log
  118. * message of level LOG_LEVEL_INFO. This is used by the components
  119. * internally and should not be used by the application.
  120. *
  121. * Messages are in the following form:
  122. * [LEVEL] (FILE: LINE_NUM) <cat_name> <message_content>
  123. */
  124. #define CAT_INFO_MSG(str) INFO_MSG("<" CAT_NAME "> " << str)
  125. /**
  126. * Prints a log message of level LOG_LEVEL_ERROR.
  127. */
  128. #define ERROR_MSG(str) PRINT_MSG(LOG_LEVEL_ERROR, str)
  129. /**
  130. * Prints a component-specific log message of level
  131. * LOG_LEVEL_ERROR. This is used by the components internally
  132. * and should not be used by the application.
  133. *
  134. * Messages are in the following form:
  135. * [LEVEL] (FILE:LINE_NUM) <comp_name> <message_content>
  136. */
  137. #define COMP_ERROR_MSG(str) ERROR_MSG("<" << comp_name << "> " << str)
  138. /**
  139. * Prints a category-specific (Component type) log message of level
  140. * LOG_LEVEL_ERROR. This is used by the components internally and
  141. * should not be used by the application.
  142. *
  143. * Messages are in the following form:
  144. * [LEVEL] (FILE:LINE_NUM) <cat_name> <message_content>
  145. */
  146. #define CAT_ERROR_MSG(str) ERROR_MSG("<" CAT_NAME "> " << str)
  147. /**
  148. * Prints a system error log message of level LOG_LEVEL_ERROR with
  149. * the string description of the errno value appended.
  150. */
  151. #define SYS_ERROR_MSG(str) ERROR_MSG(str << ": " << strerror(errno))
  152. /**
  153. * Prints a component-specific system error log message of level
  154. * LOG_LEVEL_ERROR. This is used by the components internally and
  155. * should not be used by the application.
  156. *
  157. * Messages are in the following form:
  158. * [LEVEL] (FILE:LINE_NUM) <comp_name> <message_content>
  159. */
  160. #define COMP_SYS_ERROR_MSG(str) SYS_ERROR_MSG("<" << comp_name << "> " << str)
  161. /**
  162. * Prints a category-specific (Component type) system error log
  163. * message of level LOG_LEVEL_ERROR. This is used by the components
  164. * internally and should not be used by the application.
  165. *
  166. * Messages are in the following form:
  167. * [LEVEL] (FILE:LINE_NUM) <cat_name> <message_content>
  168. */
  169. #define CAT_SYS_ERROR_MSG(str) SYS_ERROR_MSG("<" CAT_NAME "> " << str)
  170. /**
  171. * Prints a log message of level LOG_LEVEL_WARN.
  172. */
  173. #define WARN_MSG(str) PRINT_MSG(LOG_LEVEL_WARN, str)
  174. /**
  175. * Prints a component-specific log message of level LOG_LEVEL_WARN.
  176. * This is used by the components internally and should not be used by
  177. * the application.
  178. *
  179. * Messages are in the following form:
  180. * [LEVEL] (FILE:LINE_NUM) <comp_name> <message_content>
  181. */
  182. #define COMP_WARN_MSG(str) WARN_MSG("<" << comp_name << "> :" << str)
  183. /**
  184. * Print a category-specific (Component type) log message of level
  185. * LOG_LEVEL_WARN.
  186. * This is used by the components internally and should not be used by the
  187. * application.
  188. *
  189. * Messages are in the following form:
  190. * [LEVEL] (FILE:LINE_NUM) <cat_name> <message_content>
  191. */
  192. #define CAT_WARN_MSG(str) WARN_MSG("<" CAT_NAME "> " << str)
  193. /**
  194. * Prints a log message of level LOG_LEVEL_DEBUG.
  195. */
  196. #define DEBUG_MSG(str) PRINT_MSG(LOG_LEVEL_DEBUG, str)
  197. /**
  198. * Prints a component-specific log message of level LOG_LEVEL_DEBUG.
  199. * This is used by the components internally and should not be used by the
  200. * application.
  201. *
  202. * Messages are in the following form:
  203. * [LEVEL] (FILE:LINE_NUM) <comp_name> <message_content>
  204. */
  205. #define COMP_DEBUG_MSG(str) DEBUG_MSG("<" << comp_name << "> :" << str)
  206. /**
  207. * Prints a category-specific (Component type) log message of level
  208. * LOG_LEVEL_DEBUG. This is used by the components internally and
  209. * should not be used by the application.
  210. *
  211. * Messages are in the following form:
  212. * [LEVEL] (FILE:LINE_NUM) <cat_name> <message_content>
  213. */
  214. #define CAT_DEBUG_MSG(str) DEBUG_MSG("<" CAT_NAME "> " << str)
  215. #endif
  216. /** @} */