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 Y_ABSL_LOG_INTERNAL_LOG_IMPL_H_
  15. #define Y_ABSL_LOG_INTERNAL_LOG_IMPL_H_
  16. #include "y_absl/log/absl_vlog_is_on.h"
  17. #include "y_absl/log/internal/conditions.h"
  18. #include "y_absl/log/internal/log_message.h"
  19. #include "y_absl/log/internal/strip.h"
  20. // Y_ABSL_LOG()
  21. #define Y_ABSL_LOG_INTERNAL_LOG_IMPL(severity) \
  22. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
  23. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  24. // Y_ABSL_PLOG()
  25. #define Y_ABSL_LOG_INTERNAL_PLOG_IMPL(severity) \
  26. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
  27. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  28. .WithPerror()
  29. // Y_ABSL_DLOG()
  30. #ifndef NDEBUG
  31. #define Y_ABSL_LOG_INTERNAL_DLOG_IMPL(severity) \
  32. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
  33. Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  34. #else
  35. #define Y_ABSL_LOG_INTERNAL_DLOG_IMPL(severity) \
  36. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, false) \
  37. Y_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 Y_ABSL_LOG_INTERNAL_VLOG_IMPL(verbose_level) \
  43. switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
  44. case 0: \
  45. default: \
  46. Y_ABSL_LOG_INTERNAL_LOG_IF_IMPL( \
  47. _INFO, Y_ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  48. .WithVerbosity(absl_logging_internal_verbose_level)
  49. #ifndef NDEBUG
  50. #define Y_ABSL_LOG_INTERNAL_DVLOG_IMPL(verbose_level) \
  51. switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
  52. case 0: \
  53. default: \
  54. Y_ABSL_LOG_INTERNAL_DLOG_IF_IMPL( \
  55. _INFO, Y_ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  56. .WithVerbosity(absl_logging_internal_verbose_level)
  57. #else
  58. #define Y_ABSL_LOG_INTERNAL_DVLOG_IMPL(verbose_level) \
  59. switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
  60. case 0: \
  61. default: \
  62. Y_ABSL_LOG_INTERNAL_DLOG_IF_IMPL( \
  63. _INFO, false && Y_ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  64. .WithVerbosity(absl_logging_internal_verbose_level)
  65. #endif
  66. #define Y_ABSL_LOG_INTERNAL_LOG_IF_IMPL(severity, condition) \
  67. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
  68. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  69. #define Y_ABSL_LOG_INTERNAL_PLOG_IF_IMPL(severity, condition) \
  70. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
  71. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  72. .WithPerror()
  73. #ifndef NDEBUG
  74. #define Y_ABSL_LOG_INTERNAL_DLOG_IF_IMPL(severity, condition) \
  75. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
  76. Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  77. #else
  78. #define Y_ABSL_LOG_INTERNAL_DLOG_IF_IMPL(severity, condition) \
  79. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, false && (condition)) \
  80. Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  81. #endif
  82. // Y_ABSL_LOG_EVERY_N
  83. #define Y_ABSL_LOG_INTERNAL_LOG_EVERY_N_IMPL(severity, n) \
  84. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryN, n) \
  85. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  86. // Y_ABSL_LOG_FIRST_N
  87. #define Y_ABSL_LOG_INTERNAL_LOG_FIRST_N_IMPL(severity, n) \
  88. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(FirstN, n) \
  89. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  90. // Y_ABSL_LOG_EVERY_POW_2
  91. #define Y_ABSL_LOG_INTERNAL_LOG_EVERY_POW_2_IMPL(severity) \
  92. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryPow2) \
  93. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  94. // Y_ABSL_LOG_EVERY_N_SEC
  95. #define Y_ABSL_LOG_INTERNAL_LOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  96. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryNSec, n_seconds) \
  97. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  98. #define Y_ABSL_LOG_INTERNAL_PLOG_EVERY_N_IMPL(severity, n) \
  99. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryN, n) \
  100. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  101. .WithPerror()
  102. #define Y_ABSL_LOG_INTERNAL_PLOG_FIRST_N_IMPL(severity, n) \
  103. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(FirstN, n) \
  104. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  105. .WithPerror()
  106. #define Y_ABSL_LOG_INTERNAL_PLOG_EVERY_POW_2_IMPL(severity) \
  107. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryPow2) \
  108. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  109. .WithPerror()
  110. #define Y_ABSL_LOG_INTERNAL_PLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  111. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryNSec, n_seconds) \
  112. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  113. .WithPerror()
  114. #ifndef NDEBUG
  115. #define Y_ABSL_LOG_INTERNAL_DLOG_EVERY_N_IMPL(severity, n) \
  116. Y_ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  117. (EveryN, n) Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  118. #define Y_ABSL_LOG_INTERNAL_DLOG_FIRST_N_IMPL(severity, n) \
  119. Y_ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  120. (FirstN, n) Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  121. #define Y_ABSL_LOG_INTERNAL_DLOG_EVERY_POW_2_IMPL(severity) \
  122. Y_ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  123. (EveryPow2) Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  124. #define Y_ABSL_LOG_INTERNAL_DLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  125. Y_ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  126. (EveryNSec, n_seconds) Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  127. #else // def NDEBUG
  128. #define Y_ABSL_LOG_INTERNAL_DLOG_EVERY_N_IMPL(severity, n) \
  129. Y_ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  130. (EveryN, n) Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  131. #define Y_ABSL_LOG_INTERNAL_DLOG_FIRST_N_IMPL(severity, n) \
  132. Y_ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  133. (FirstN, n) Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  134. #define Y_ABSL_LOG_INTERNAL_DLOG_EVERY_POW_2_IMPL(severity) \
  135. Y_ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  136. (EveryPow2) Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  137. #define Y_ABSL_LOG_INTERNAL_DLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  138. Y_ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  139. (EveryNSec, n_seconds) Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  140. #endif // def NDEBUG
  141. #define Y_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. Y_ABSL_LOG_INTERNAL_CONDITION_INFO( \
  146. STATEFUL, Y_ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  147. (EveryN, n) Y_ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
  148. absl_logging_internal_verbose_level)
  149. #define Y_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. Y_ABSL_LOG_INTERNAL_CONDITION_INFO( \
  154. STATEFUL, Y_ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  155. (FirstN, n) Y_ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
  156. absl_logging_internal_verbose_level)
  157. #define Y_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. Y_ABSL_LOG_INTERNAL_CONDITION_INFO( \
  162. STATEFUL, Y_ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  163. (EveryPow2) Y_ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
  164. absl_logging_internal_verbose_level)
  165. #define Y_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. Y_ABSL_LOG_INTERNAL_CONDITION_INFO( \
  170. STATEFUL, Y_ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
  171. (EveryNSec, n_seconds) Y_ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream() \
  172. .WithVerbosity(absl_logging_internal_verbose_level)
  173. #define Y_ABSL_LOG_INTERNAL_LOG_IF_EVERY_N_IMPL(severity, condition, n) \
  174. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
  175. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  176. #define Y_ABSL_LOG_INTERNAL_LOG_IF_FIRST_N_IMPL(severity, condition, n) \
  177. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
  178. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  179. #define Y_ABSL_LOG_INTERNAL_LOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  180. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
  181. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  182. #define Y_ABSL_LOG_INTERNAL_LOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
  183. n_seconds) \
  184. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
  185. n_seconds) \
  186. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  187. #define Y_ABSL_LOG_INTERNAL_PLOG_IF_EVERY_N_IMPL(severity, condition, n) \
  188. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
  189. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  190. .WithPerror()
  191. #define Y_ABSL_LOG_INTERNAL_PLOG_IF_FIRST_N_IMPL(severity, condition, n) \
  192. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
  193. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  194. .WithPerror()
  195. #define Y_ABSL_LOG_INTERNAL_PLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  196. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
  197. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  198. .WithPerror()
  199. #define Y_ABSL_LOG_INTERNAL_PLOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
  200. n_seconds) \
  201. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
  202. n_seconds) \
  203. Y_ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  204. .WithPerror()
  205. #ifndef NDEBUG
  206. #define Y_ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_IMPL(severity, condition, n) \
  207. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
  208. Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  209. #define Y_ABSL_LOG_INTERNAL_DLOG_IF_FIRST_N_IMPL(severity, condition, n) \
  210. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
  211. Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  212. #define Y_ABSL_LOG_INTERNAL_DLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  213. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
  214. Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  215. #define Y_ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
  216. n_seconds) \
  217. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
  218. n_seconds) \
  219. Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  220. #else // def NDEBUG
  221. #define Y_ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_IMPL(severity, condition, n) \
  222. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  223. EveryN, n) Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  224. #define Y_ABSL_LOG_INTERNAL_DLOG_IF_FIRST_N_IMPL(severity, condition, n) \
  225. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  226. FirstN, n) Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  227. #define Y_ABSL_LOG_INTERNAL_DLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  228. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  229. EveryPow2) Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  230. #define Y_ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
  231. n_seconds) \
  232. Y_ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  233. EveryNSec, n_seconds) \
  234. Y_ABSL_LOGGING_INTERNAL_DLOG##severity.InternalStream()
  235. #endif // def NDEBUG
  236. #endif // Y_ABSL_LOG_INTERNAL_LOG_IMPL_H_