log_impl.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // Copyright 2022 The Abseil Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef ABSL_LOG_INTERNAL_LOG_IMPL_H_
  15. #define ABSL_LOG_INTERNAL_LOG_IMPL_H_
  16. #include "absl/log/absl_vlog_is_on.h"
  17. #include "absl/log/internal/conditions.h"
  18. #include "absl/log/internal/log_message.h"
  19. #include "absl/log/internal/strip.h"
  20. // ABSL_LOG()
  21. #define ABSL_LOG_INTERNAL_LOG_IMPL(severity) \
  22. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
  23. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  24. // ABSL_PLOG()
  25. #define ABSL_LOG_INTERNAL_PLOG_IMPL(severity) \
  26. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
  27. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  28. .WithPerror()
  29. // ABSL_DLOG()
  30. #ifndef NDEBUG
  31. #define ABSL_LOG_INTERNAL_DLOG_IMPL(severity) \
  32. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
  33. ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  34. #else
  35. #define ABSL_LOG_INTERNAL_DLOG_IMPL(severity) \
  36. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, false) \
  37. ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  38. #endif
  39. // The `switch` ensures that this expansion is the beginning of a statement (as
  40. // opposed to an expression). The use of both `case 0` and `default` is to
  41. // suppress a compiler warning.
  42. #define ABSL_LOG_INTERNAL_VLOG_IMPL(verbose_level) \
  43. switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
  44. case 0: \
  45. default: \
  46. ABSL_LOG_INTERNAL_LOG_IF_IMPL( \
  47. _INFO, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  48. .WithVerbosity(absl_logging_internal_verbose_level)
  49. #ifndef NDEBUG
  50. #define ABSL_LOG_INTERNAL_DVLOG_IMPL(verbose_level) \
  51. switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
  52. case 0: \
  53. default: \
  54. ABSL_LOG_INTERNAL_DLOG_IF_IMPL( \
  55. _INFO, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  56. .WithVerbosity(absl_logging_internal_verbose_level)
  57. #else
  58. #define ABSL_LOG_INTERNAL_DVLOG_IMPL(verbose_level) \
  59. switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
  60. case 0: \
  61. default: \
  62. ABSL_LOG_INTERNAL_DLOG_IF_IMPL( \
  63. _INFO, false && ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  64. .WithVerbosity(absl_logging_internal_verbose_level)
  65. #endif
  66. #define ABSL_LOG_INTERNAL_LOG_IF_IMPL(severity, condition) \
  67. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
  68. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  69. #define ABSL_LOG_INTERNAL_PLOG_IF_IMPL(severity, condition) \
  70. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
  71. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  72. .WithPerror()
  73. #ifndef NDEBUG
  74. #define ABSL_LOG_INTERNAL_DLOG_IF_IMPL(severity, condition) \
  75. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
  76. ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  77. #else
  78. #define ABSL_LOG_INTERNAL_DLOG_IF_IMPL(severity, condition) \
  79. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, false && (condition)) \
  80. ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  81. #endif
  82. // ABSL_LOG_EVERY_N
  83. #define ABSL_LOG_INTERNAL_LOG_EVERY_N_IMPL(severity, n) \
  84. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryN, n) \
  85. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  86. // ABSL_LOG_FIRST_N
  87. #define ABSL_LOG_INTERNAL_LOG_FIRST_N_IMPL(severity, n) \
  88. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(FirstN, n) \
  89. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  90. // ABSL_LOG_EVERY_POW_2
  91. #define ABSL_LOG_INTERNAL_LOG_EVERY_POW_2_IMPL(severity) \
  92. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryPow2) \
  93. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  94. // ABSL_LOG_EVERY_N_SEC
  95. #define ABSL_LOG_INTERNAL_LOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  96. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryNSec, n_seconds) \
  97. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  98. #define ABSL_LOG_INTERNAL_PLOG_EVERY_N_IMPL(severity, n) \
  99. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryN, n) \
  100. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  101. .WithPerror()
  102. #define ABSL_LOG_INTERNAL_PLOG_FIRST_N_IMPL(severity, n) \
  103. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(FirstN, n) \
  104. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  105. .WithPerror()
  106. #define ABSL_LOG_INTERNAL_PLOG_EVERY_POW_2_IMPL(severity) \
  107. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryPow2) \
  108. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  109. .WithPerror()
  110. #define ABSL_LOG_INTERNAL_PLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  111. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryNSec, n_seconds) \
  112. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  113. .WithPerror()
  114. #ifndef NDEBUG
  115. #define ABSL_LOG_INTERNAL_DLOG_EVERY_N_IMPL(severity, n) \
  116. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  117. (EveryN, n) ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  118. #define ABSL_LOG_INTERNAL_DLOG_FIRST_N_IMPL(severity, n) \
  119. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  120. (FirstN, n) ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  121. #define ABSL_LOG_INTERNAL_DLOG_EVERY_POW_2_IMPL(severity) \
  122. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  123. (EveryPow2) ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  124. #define ABSL_LOG_INTERNAL_DLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  125. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  126. (EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  127. #else // def NDEBUG
  128. #define ABSL_LOG_INTERNAL_DLOG_EVERY_N_IMPL(severity, n) \
  129. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  130. (EveryN, n) ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  131. #define ABSL_LOG_INTERNAL_DLOG_FIRST_N_IMPL(severity, n) \
  132. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  133. (FirstN, n) ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  134. #define ABSL_LOG_INTERNAL_DLOG_EVERY_POW_2_IMPL(severity) \
  135. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  136. (EveryPow2) ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  137. #define ABSL_LOG_INTERNAL_DLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  138. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  139. (EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  140. #endif // def NDEBUG
  141. #define ABSL_LOG_INTERNAL_VLOG_EVERY_N_IMPL(verbose_level, n) \
  142. switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
  143. case 0: \
  144. default: \
  145. ABSL_LOG_INTERNAL_CONDITION_INFO( \
  146. STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  147. (EveryN, n) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
  148. absl_logging_internal_verbose_level)
  149. #define ABSL_LOG_INTERNAL_VLOG_FIRST_N_IMPL(verbose_level, n) \
  150. switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
  151. case 0: \
  152. default: \
  153. ABSL_LOG_INTERNAL_CONDITION_INFO( \
  154. STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  155. (FirstN, n) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
  156. absl_logging_internal_verbose_level)
  157. #define ABSL_LOG_INTERNAL_VLOG_EVERY_POW_2_IMPL(verbose_level) \
  158. switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
  159. case 0: \
  160. default: \
  161. ABSL_LOG_INTERNAL_CONDITION_INFO( \
  162. STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  163. (EveryPow2) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
  164. absl_logging_internal_verbose_level)
  165. #define ABSL_LOG_INTERNAL_VLOG_EVERY_N_SEC_IMPL(verbose_level, n_seconds) \
  166. switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
  167. case 0: \
  168. default: \
  169. ABSL_LOG_INTERNAL_CONDITION_INFO( \
  170. STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  171. (EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream() \
  172. .WithVerbosity(absl_logging_internal_verbose_level)
  173. #define ABSL_LOG_INTERNAL_LOG_IF_EVERY_N_IMPL(severity, condition, n) \
  174. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
  175. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  176. #define ABSL_LOG_INTERNAL_LOG_IF_FIRST_N_IMPL(severity, condition, n) \
  177. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
  178. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  179. #define ABSL_LOG_INTERNAL_LOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  180. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
  181. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  182. #define ABSL_LOG_INTERNAL_LOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
  183. n_seconds) \
  184. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
  185. n_seconds) \
  186. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  187. #define ABSL_LOG_INTERNAL_PLOG_IF_EVERY_N_IMPL(severity, condition, n) \
  188. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
  189. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  190. .WithPerror()
  191. #define ABSL_LOG_INTERNAL_PLOG_IF_FIRST_N_IMPL(severity, condition, n) \
  192. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
  193. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  194. .WithPerror()
  195. #define ABSL_LOG_INTERNAL_PLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  196. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
  197. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  198. .WithPerror()
  199. #define ABSL_LOG_INTERNAL_PLOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
  200. n_seconds) \
  201. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
  202. n_seconds) \
  203. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  204. .WithPerror()
  205. #ifndef NDEBUG
  206. #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_IMPL(severity, condition, n) \
  207. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
  208. ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  209. #define ABSL_LOG_INTERNAL_DLOG_IF_FIRST_N_IMPL(severity, condition, n) \
  210. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
  211. ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  212. #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  213. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
  214. ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  215. #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
  216. n_seconds) \
  217. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
  218. n_seconds) \
  219. ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  220. #else // def NDEBUG
  221. #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_IMPL(severity, condition, n) \
  222. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  223. EveryN, n) ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  224. #define ABSL_LOG_INTERNAL_DLOG_IF_FIRST_N_IMPL(severity, condition, n) \
  225. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  226. FirstN, n) ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  227. #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  228. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  229. EveryPow2) ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  230. #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
  231. n_seconds) \
  232. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  233. EveryNSec, n_seconds) \
  234. ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  235. #endif // def NDEBUG
  236. #endif // ABSL_LOG_INTERNAL_LOG_IMPL_H_