You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

283 lines
10 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/trace.h
  3. *
  4. * Purpose: Pantheios Tracing API.
  5. *
  6. * Created: 11th November 2007
  7. * Updated: 23rd July 2010
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2007-2010, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are
  16. * met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  24. * names of any contributors may be used to endorse or promote products
  25. * derived from this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file pantheios/trace.h
  41. *
  42. * [C, C++] Include file for the \ref group__tracing
  43. */
  44. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_TRACE
  45. #define PANTHEIOS_INCL_PANTHEIOS_H_TRACE
  46. /* /////////////////////////////////////////////////////////////////////////
  47. * Version information
  48. */
  49. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  50. # define PANTHEIOS_VER_PANTHEIOS_H_TRACE_MAJOR 1
  51. # define PANTHEIOS_VER_PANTHEIOS_H_TRACE_MINOR 3
  52. # define PANTHEIOS_VER_PANTHEIOS_H_TRACE_REVISION 1
  53. # define PANTHEIOS_VER_PANTHEIOS_H_TRACE_EDIT 16
  54. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  55. /* /////////////////////////////////////////////////////////////////////////
  56. * Includes
  57. */
  58. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  59. # include <pantheios/pantheios.h>
  60. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  61. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_FILELINE
  62. # include <pantheios/fileline.h>
  63. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_FILELINE */
  64. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  65. # error The Pantheios Tracing API is currently only supported in multibyte builds
  66. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  67. #include <stlsoft/stlsoft.h>
  68. /* /////////////////////////////////////////////////////////////////////////
  69. * Tracing features
  70. */
  71. /** \defgroup group__tracing Pantheios Tracing API
  72. *
  73. * Pantheios Tracing API
  74. *
  75. * If your compiler supports variadic macros, you may use this to log by
  76. * "tracing", where your log statement is preceded by
  77. * "<file>(<line>): ", or "<file>: ", and so on, or a custom value.
  78. *
  79. * The Pantheios Tracing API consists of:
  80. *
  81. * - PANTHEIOS_TRACE_PRINTF() - uses pantheios::printf
  82. * - PANTHEIOS_TRACE() - uses pantheios::log
  83. * - PANTHEIOS_TRACE_EMERGENCY() - uses pantheios::log_EMERGENCY
  84. * - PANTHEIOS_TRACE_ALERT() - uses pantheios::log_ALERT
  85. * - PANTHEIOS_TRACE_CRITICAL() - uses pantheios::log_CRITICAL
  86. * - PANTHEIOS_TRACE_ERROR() - uses pantheios::log_ERROR
  87. * - PANTHEIOS_TRACE_WARNING() - uses pantheios::log_WARNING
  88. * - PANTHEIOS_TRACE_NOTICE() - uses pantheios::log_NOTICE
  89. * - PANTHEIOS_TRACE_INFORMATIONAL() - uses pantheios::log_INFORMATIONAL
  90. * - PANTHEIOS_TRACE_DEBUG() - uses pantheios::log_DEBUG
  91. *
  92. * By default, support for variadic macros is via the STLSoft
  93. * preprocessor symbol, STLSOFT_CF_SUPPORTS_VARIADIC_MACROS. If that is
  94. * defined, and you have *not* defined PANTHEIOS_NO_USE_VARIADIC_MACROS,
  95. * then the symbol PANTHEIOS_USES_VARIADIC_MACROS will be defined, and
  96. * the various aspects of the Pantheios tracing api described above will be
  97. * available to you.
  98. *
  99. * If you _know_ that your compiler supports variadics even when STLSoft
  100. * thinks that it does not, you can just define
  101. * PANTHEIOS_USES_VARIADIC_MACROS yourself.
  102. *
  103. * By default, the prefix is of the form "<file>(<line>): ", but you can
  104. * override it to whatever you want by redefining PANTHEIOS_TRACE_PREFIX.
  105. */
  106. #if defined(STLSOFT_CF_SUPPORTS_VARIADIC_MACROS) && \
  107. !defined(PANTHEIOS_NO_USE_VARIADIC_MACROS)
  108. # define PANTHEIOS_USES_VARIADIC_MACROS
  109. #endif /* STLSOFT_CF_SUPPORTS_VARIADIC_MACROS && !PANTHEIOS_NO_USE_VARIADIC_MACROS */
  110. /** \def PANTHEIOS_TRACE_PREFIX
  111. *
  112. * The file-line prefix uses by the \ref group__tracing for C constructs. It
  113. * defaults to PANTHEIOS_FILELINE, but may be \#define'd by the user to be
  114. * something else, as desired.
  115. *
  116. * \ingroup group__tracing
  117. */
  118. /** \def PANTHEIOS_TRACE_LOG_PREFIX
  119. *
  120. * The file-line prefix uses by the \ref group__tracing for C++ constructs.
  121. * It defaults to <code>pantheios::pan_slice_t(PANTHEIOS_FILELINE)</code>,
  122. * but may be \#define'd by the user to be something else, as desired.
  123. *
  124. * \ingroup group__tracing
  125. */
  126. /* Now define the prefix, if the user has not already done so. */
  127. # if !defined(PANTHEIOS_TRACE_PREFIX)
  128. # define PANTHEIOS_TRACE_PREFIX PANTHEIOS_FILELINE
  129. # ifdef __cplusplus
  130. # define PANTHEIOS_TRACE_LOG_PREFIX ::pantheios::pan_slice_t(PANTHEIOS_FILELINE, STLSOFT_NUM_ELEMENTS(PANTHEIOS_FILELINE) - 1)
  131. # else /* ? __cplusplus */
  132. # define PANTHEIOS_TRACE_LOG_PREFIX PANTHEIOS_FILELINE
  133. # endif /* __cplusplus */
  134. # else /* ? PANTHEIOS_TRACE_PREFIX */
  135. # define PANTHEIOS_TRACE_LOG_PREFIX PANTHEIOS_TRACE_PREFIX
  136. # endif /* !PANTHEIOS_TRACE_PREFIX */
  137. /* Now define the Pantheios Tracing API */
  138. #if defined(PANTHEIOS_USES_VARIADIC_MACROS) || \
  139. defined(PANTHEIOS_DOCUMENTATION_SKIP_SECTION)
  140. /** \def PANTHEIOS_TRACE_PRINTF
  141. *
  142. * Logs a printf()-formatted statement with a file+line prefix, at the
  143. * given severity level
  144. *
  145. * \ingroup group__tracing
  146. *
  147. * \param sev The severity level
  148. * \param fmt The format string
  149. */
  150. # if !defined(PANTHEIOS_NO_NAMESPACE) || \
  151. defined(PANTHEIOS_DOCUMENTATION_SKIP_SECTION)
  152. # define PANTHEIOS_TRACE_PRINTF(sev, fmt, ...) ::pantheios::pantheios_logprintf((sev), "%s" fmt, stlsoft_static_cast(PANTHEIOS_NS_QUAL(pan_char_t) const*, PANTHEIOS_TRACE_PREFIX), __VA_ARGS__)
  153. # else /* ? __cplusplus */
  154. # define PANTHEIOS_TRACE_PRINTF(sev, fmt, ...) pantheios_logprintf((sev), "%s" fmt, stlsoft_static_cast(PANTHEIOS_NS_QUAL(pan_char_t) const*, PANTHEIOS_TRACE_PREFIX), __VA_ARGS__)
  155. # endif /* __cplusplus */
  156. # if !defined(PANTHEIOS_NO_NAMESPACE) || \
  157. defined(PANTHEIOS_DOCUMENTATION_SKIP_SECTION)
  158. /** \def PANTHEIOS_TRACE
  159. *
  160. * Logs a multi-argument statement with a file+line prefix, at the
  161. * given severity level
  162. *
  163. * \ingroup group__tracing
  164. *
  165. * \param sev The severity level
  166. */
  167. /** \def PANTHEIOS_TRACE_EMERGENCY
  168. *
  169. * Logs a multi-argument statement with a file+line prefix, at the
  170. * pantheios::EMERGENCY severity level
  171. *
  172. * \ingroup group__tracing
  173. */
  174. /** \def PANTHEIOS_TRACE_ALERT
  175. *
  176. * Logs a multi-argument statement with a file+line prefix, at the
  177. * pantheios::ALERT severity level
  178. *
  179. * \ingroup group__tracing
  180. */
  181. /** \def PANTHEIOS_TRACE_CRITICAL
  182. *
  183. * Logs a multi-argument statement with a file+line prefix, at the
  184. * pantheios::CRITICAL severity level
  185. *
  186. * \ingroup group__tracing
  187. */
  188. /** \def PANTHEIOS_TRACE_ERROR
  189. *
  190. * Logs a multi-argument statement with a file+line prefix, at the
  191. * pantheios::ERROR severity level
  192. *
  193. * \ingroup group__tracing
  194. */
  195. /** \def PANTHEIOS_TRACE_WARNING
  196. *
  197. * Logs a multi-argument statement with a file+line prefix, at the
  198. * pantheios::WARNING severity level
  199. *
  200. * \ingroup group__tracing
  201. */
  202. /** \def PANTHEIOS_TRACE_NOTICE
  203. *
  204. * Logs a multi-argument statement with a file+line prefix, at the
  205. * pantheios::NOTICE severity level
  206. *
  207. * \ingroup group__tracing
  208. */
  209. /** \def PANTHEIOS_TRACE_INFORMATIONAL
  210. *
  211. * Logs a multi-argument statement with a file+line prefix, at the
  212. * pantheios::INFORMATIONAL severity level
  213. *
  214. * \ingroup group__tracing
  215. */
  216. /** \def PANTHEIOS_TRACE_DEBUG
  217. *
  218. * Logs a multi-argument statement with a file+line prefix, at the
  219. * pantheios::DEBUG severity level
  220. *
  221. * \ingroup group__tracing
  222. */
  223. # define PANTHEIOS_TRACE(sev, ...) ::pantheios::log((sev), PANTHEIOS_TRACE_LOG_PREFIX, __VA_ARGS__)
  224. # if !defined(PANTHEIOS_NO_STOCK_LEVELS)
  225. # define PANTHEIOS_TRACE_EMERGENCY(...) ::pantheios::log(PANTHEIOS_SEV_EMERGENCY, PANTHEIOS_TRACE_LOG_PREFIX, __VA_ARGS__)
  226. # define PANTHEIOS_TRACE_ALERT(...) ::pantheios::log(PANTHEIOS_SEV_ALERT, PANTHEIOS_TRACE_LOG_PREFIX, __VA_ARGS__)
  227. # define PANTHEIOS_TRACE_CRITICAL(...) ::pantheios::log(PANTHEIOS_SEV_CRITICAL, PANTHEIOS_TRACE_LOG_PREFIX, __VA_ARGS__)
  228. # define PANTHEIOS_TRACE_ERROR(...) ::pantheios::log(PANTHEIOS_SEV_ERROR, PANTHEIOS_TRACE_LOG_PREFIX, __VA_ARGS__)
  229. # define PANTHEIOS_TRACE_WARNING(...) ::pantheios::log(PANTHEIOS_SEV_WARNING, PANTHEIOS_TRACE_LOG_PREFIX, __VA_ARGS__)
  230. # define PANTHEIOS_TRACE_NOTICE(...) ::pantheios::log(PANTHEIOS_SEV_NOTICE, PANTHEIOS_TRACE_LOG_PREFIX, __VA_ARGS__)
  231. # define PANTHEIOS_TRACE_INFORMATIONAL(...) ::pantheios::log(PANTHEIOS_SEV_INFORMATIONAL, PANTHEIOS_TRACE_LOG_PREFIX, __VA_ARGS__)
  232. # define PANTHEIOS_TRACE_DEBUG(...) ::pantheios::log(PANTHEIOS_SEV_DEBUG, PANTHEIOS_TRACE_LOG_PREFIX, __VA_ARGS__)
  233. # endif /* !PANTHEIOS_NO_STOCK_LEVELS */
  234. # endif /* __cplusplus */
  235. #endif /* PANTHEIOS_USES_VARIADIC_MACROS */
  236. /* /////////////////////////////////////////////////////////////////////////
  237. * Inclusion
  238. */
  239. #ifdef STLSOFT_PPF_pragma_once_SUPPORT
  240. # pragma once
  241. #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
  242. /* ////////////////////////////////////////////////////////////////////// */
  243. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_TRACE */
  244. /* ///////////////////////////// end of file //////////////////////////// */