log_impl.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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/internal/conditions.h"
  17. #include "absl/log/internal/log_message.h"
  18. #include "absl/log/internal/strip.h"
  19. // ABSL_LOG()
  20. #define ABSL_LOG_IMPL(severity) \
  21. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
  22. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  23. // ABSL_PLOG()
  24. #define ABSL_PLOG_IMPL(severity) \
  25. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
  26. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  27. .WithPerror()
  28. // ABSL_DLOG()
  29. #ifndef NDEBUG
  30. #define ABSL_DLOG_IMPL(severity) \
  31. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
  32. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  33. #else
  34. #define ABSL_DLOG_IMPL(severity) \
  35. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, false) \
  36. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  37. #endif
  38. #define ABSL_LOG_IF_IMPL(severity, condition) \
  39. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
  40. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  41. #define ABSL_PLOG_IF_IMPL(severity, condition) \
  42. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
  43. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  44. .WithPerror()
  45. #ifndef NDEBUG
  46. #define ABSL_DLOG_IF_IMPL(severity, condition) \
  47. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
  48. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  49. #else
  50. #define ABSL_DLOG_IF_IMPL(severity, condition) \
  51. ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, false && (condition)) \
  52. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  53. #endif
  54. // ABSL_LOG_EVERY_N
  55. #define ABSL_LOG_EVERY_N_IMPL(severity, n) \
  56. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryN, n) \
  57. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  58. // ABSL_LOG_FIRST_N
  59. #define ABSL_LOG_FIRST_N_IMPL(severity, n) \
  60. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(FirstN, n) \
  61. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  62. // ABSL_LOG_EVERY_POW_2
  63. #define ABSL_LOG_EVERY_POW_2_IMPL(severity) \
  64. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryPow2) \
  65. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  66. // ABSL_LOG_EVERY_N_SEC
  67. #define ABSL_LOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  68. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryNSec, n_seconds) \
  69. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  70. #define ABSL_PLOG_EVERY_N_IMPL(severity, n) \
  71. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryN, n) \
  72. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  73. .WithPerror()
  74. #define ABSL_PLOG_FIRST_N_IMPL(severity, n) \
  75. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(FirstN, n) \
  76. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  77. .WithPerror()
  78. #define ABSL_PLOG_EVERY_POW_2_IMPL(severity) \
  79. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryPow2) \
  80. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  81. .WithPerror()
  82. #define ABSL_PLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  83. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryNSec, n_seconds) \
  84. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  85. .WithPerror()
  86. #ifndef NDEBUG
  87. #define ABSL_DLOG_EVERY_N_IMPL(severity, n) \
  88. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  89. (EveryN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  90. #define ABSL_DLOG_FIRST_N_IMPL(severity, n) \
  91. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  92. (FirstN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  93. #define ABSL_DLOG_EVERY_POW_2_IMPL(severity) \
  94. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  95. (EveryPow2) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  96. #define ABSL_DLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  97. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
  98. (EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  99. #else // def NDEBUG
  100. #define ABSL_DLOG_EVERY_N_IMPL(severity, n) \
  101. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  102. (EveryN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  103. #define ABSL_DLOG_FIRST_N_IMPL(severity, n) \
  104. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  105. (FirstN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  106. #define ABSL_DLOG_EVERY_POW_2_IMPL(severity) \
  107. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  108. (EveryPow2) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  109. #define ABSL_DLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
  110. ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
  111. (EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  112. #endif // def NDEBUG
  113. #define ABSL_LOG_IF_EVERY_N_IMPL(severity, condition, n) \
  114. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
  115. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  116. #define ABSL_LOG_IF_FIRST_N_IMPL(severity, condition, n) \
  117. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
  118. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  119. #define ABSL_LOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  120. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
  121. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  122. #define ABSL_LOG_IF_EVERY_N_SEC_IMPL(severity, condition, n_seconds) \
  123. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
  124. n_seconds) \
  125. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  126. #define ABSL_PLOG_IF_EVERY_N_IMPL(severity, condition, n) \
  127. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
  128. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  129. .WithPerror()
  130. #define ABSL_PLOG_IF_FIRST_N_IMPL(severity, condition, n) \
  131. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
  132. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  133. .WithPerror()
  134. #define ABSL_PLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  135. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
  136. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  137. .WithPerror()
  138. #define ABSL_PLOG_IF_EVERY_N_SEC_IMPL(severity, condition, n_seconds) \
  139. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
  140. n_seconds) \
  141. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
  142. .WithPerror()
  143. #ifndef NDEBUG
  144. #define ABSL_DLOG_IF_EVERY_N_IMPL(severity, condition, n) \
  145. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
  146. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  147. #define ABSL_DLOG_IF_FIRST_N_IMPL(severity, condition, n) \
  148. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
  149. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  150. #define ABSL_DLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  151. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
  152. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  153. #define ABSL_DLOG_IF_EVERY_N_SEC_IMPL(severity, condition, n_seconds) \
  154. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
  155. n_seconds) \
  156. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  157. #else // def NDEBUG
  158. #define ABSL_DLOG_IF_EVERY_N_IMPL(severity, condition, n) \
  159. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  160. EveryN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  161. #define ABSL_DLOG_IF_FIRST_N_IMPL(severity, condition, n) \
  162. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  163. FirstN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  164. #define ABSL_DLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
  165. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  166. EveryPow2) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  167. #define ABSL_DLOG_IF_EVERY_N_SEC_IMPL(severity, condition, n_seconds) \
  168. ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
  169. EveryNSec, n_seconds) \
  170. ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
  171. #endif // def NDEBUG
  172. #endif // ABSL_LOG_INTERNAL_LOG_IMPL_H_