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