23
23
#include < iostream>
24
24
#include < vector>
25
25
26
+ #define TRANTOR_IF_ (cond ) for (int _r = 0 ; _r == 0 && (cond); _r = 1 )
27
+
26
28
namespace trantor
27
29
{
28
30
/* *
@@ -219,36 +221,36 @@ class TRANTOR_EXPORT RawLogger : public NonCopyable
219
221
};
220
222
#ifdef NDEBUG
221
223
#define LOG_TRACE \
222
- if (0 ) \
224
+ TRANTOR_IF_ (0 ) \
223
225
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kTrace , __func__) \
224
226
.stream()
225
227
#else
226
228
#define LOG_TRACE \
227
- if (trantor::Logger::logLevel() <= trantor::Logger::kTrace ) \
229
+ TRANTOR_IF_ (trantor::Logger::logLevel() <= trantor::Logger::kTrace) \
228
230
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kTrace , __func__) \
229
231
.stream()
230
232
#define LOG_TRACE_TO (index ) \
231
- if (trantor::Logger::logLevel() <= trantor::Logger::kTrace ) \
233
+ TRANTOR_IF_ (trantor::Logger::logLevel() <= trantor::Logger::kTrace) \
232
234
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kTrace , __func__) \
233
235
.setIndex(index) \
234
236
.stream()
235
237
236
238
#endif
237
239
238
240
#define LOG_DEBUG \
239
- if (trantor::Logger::logLevel() <= trantor::Logger::kDebug ) \
241
+ TRANTOR_IF_ (trantor::Logger::logLevel() <= trantor::Logger::kDebug ) \
240
242
trantor::Logger (__FILE__, __LINE__, trantor::Logger::kDebug , __func__) \
241
243
.stream()
242
244
#define LOG_DEBUG_TO (index ) \
243
- if (trantor::Logger::logLevel() <= trantor::Logger::kDebug ) \
245
+ TRANTOR_IF_ (trantor::Logger::logLevel() <= trantor::Logger::kDebug ) \
244
246
trantor::Logger (__FILE__, __LINE__, trantor::Logger::kDebug , __func__) \
245
247
.setIndex(index) \
246
248
.stream()
247
- #define LOG_INFO \
248
- if (trantor::Logger::logLevel() <= trantor::Logger::kInfo ) \
249
+ #define LOG_INFO \
250
+ TRANTOR_IF_ (trantor::Logger::logLevel() <= trantor::Logger::kInfo ) \
249
251
trantor::Logger (__FILE__, __LINE__).stream()
250
- #define LOG_INFO_TO (index ) \
251
- if (trantor::Logger::logLevel() <= trantor::Logger::kInfo ) \
252
+ #define LOG_INFO_TO (index ) \
253
+ TRANTOR_IF_ (trantor::Logger::logLevel() <= trantor::Logger::kInfo ) \
252
254
trantor::Logger (__FILE__, __LINE__).setIndex(index).stream()
253
255
#define LOG_WARN \
254
256
trantor::Logger (__FILE__, __LINE__, trantor::Logger::kWarn ).stream()
@@ -276,79 +278,82 @@ class TRANTOR_EXPORT RawLogger : public NonCopyable
276
278
#define LOG_RAW_TO (index ) trantor::RawLogger().setIndex(index).stream()
277
279
278
280
#define LOG_TRACE_IF (cond ) \
279
- if ((trantor::Logger::logLevel() <= trantor::Logger::kTrace ) && (cond)) \
281
+ TRANTOR_IF_ ((trantor::Logger::logLevel() <= trantor::Logger::kTrace ) && \
282
+ (cond)) \
280
283
trantor::Logger (__FILE__, __LINE__, trantor::Logger::kTrace , __func__) \
281
284
.stream()
282
285
#define LOG_DEBUG_IF (cond ) \
283
- if ((trantor::Logger::logLevel() <= trantor::Logger::kDebug ) && (cond)) \
286
+ TRANTOR_IF_ ((trantor::Logger::logLevel() <= trantor::Logger::kDebug ) && \
287
+ (cond)) \
284
288
trantor::Logger (__FILE__, __LINE__, trantor::Logger::kDebug , __func__) \
285
289
.stream()
286
290
#define LOG_INFO_IF (cond ) \
287
- if ((trantor::Logger::logLevel() <= trantor::Logger::kInfo ) && (cond)) \
291
+ TRANTOR_IF_ ((trantor::Logger::logLevel() <= trantor::Logger::kInfo ) && \
292
+ (cond)) \
288
293
trantor::Logger (__FILE__, __LINE__).stream()
289
294
#define LOG_WARN_IF (cond ) \
290
- if (cond) \
295
+ TRANTOR_IF_ (cond) \
291
296
trantor::Logger (__FILE__, __LINE__, trantor::Logger::kWarn ).stream()
292
297
#define LOG_ERROR_IF (cond ) \
293
- if (cond) \
298
+ TRANTOR_IF_ (cond) \
294
299
trantor::Logger (__FILE__, __LINE__, trantor::Logger::kError ).stream()
295
300
#define LOG_FATAL_IF (cond ) \
296
- if (cond) \
301
+ TRANTOR_IF_ (cond) \
297
302
trantor::Logger (__FILE__, __LINE__, trantor::Logger::kFatal ).stream()
298
303
299
304
#ifdef NDEBUG
300
305
#define DLOG_TRACE \
301
- if (0 ) \
306
+ TRANTOR_IF_ (0 ) \
302
307
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kTrace , __func__) \
303
308
.stream()
304
309
#define DLOG_DEBUG \
305
- if (0 ) \
310
+ TRANTOR_IF_ (0 ) \
306
311
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kDebug , __func__) \
307
312
.stream()
308
- #define DLOG_INFO \
309
- if (0 ) \
313
+ #define DLOG_INFO \
314
+ TRANTOR_IF_ (0 ) \
310
315
trantor::Logger(__FILE__, __LINE__).stream()
311
- #define DLOG_WARN \
312
- if (0 ) \
316
+ #define DLOG_WARN \
317
+ TRANTOR_IF_ (0 ) \
313
318
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kWarn ).stream()
314
319
#define DLOG_ERROR \
315
- if (0 ) \
320
+ TRANTOR_IF_ (0 ) \
316
321
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kError ).stream()
317
322
#define DLOG_FATAL \
318
- if (0 ) \
323
+ TRANTOR_IF_ (0 ) \
319
324
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kFatal ).stream()
320
325
321
326
#define DLOG_TRACE_IF (cond ) \
322
- if (0 ) \
327
+ TRANTOR_IF_ (0 ) \
323
328
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kTrace , __func__) \
324
329
.stream()
325
330
#define DLOG_DEBUG_IF (cond ) \
326
- if (0 ) \
331
+ TRANTOR_IF_ (0 ) \
327
332
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kDebug , __func__) \
328
333
.stream()
329
334
#define DLOG_INFO_IF (cond ) \
330
- if (0 ) \
335
+ TRANTOR_IF_ (0 ) \
331
336
trantor::Logger(__FILE__, __LINE__).stream()
332
337
#define DLOG_WARN_IF (cond ) \
333
- if (0 ) \
338
+ TRANTOR_IF_ (0 ) \
334
339
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kWarn ).stream()
335
340
#define DLOG_ERROR_IF (cond ) \
336
- if (0 ) \
341
+ TRANTOR_IF_ (0 ) \
337
342
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kError ).stream()
338
343
#define DLOG_FATAL_IF (cond ) \
339
- if (0 ) \
344
+ TRANTOR_IF_ (0 ) \
340
345
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kFatal ).stream()
341
346
#else
342
347
#define DLOG_TRACE \
343
- if (trantor::Logger::logLevel() <= trantor::Logger::kTrace ) \
348
+ TRANTOR_IF_ (trantor::Logger::logLevel() <= trantor::Logger::kTrace) \
344
349
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kTrace , __func__) \
345
350
.stream()
346
351
#define DLOG_DEBUG \
347
- if (trantor::Logger::logLevel() <= trantor::Logger::kDebug ) \
352
+ TRANTOR_IF_ (trantor::Logger::logLevel() <= trantor::Logger::kDebug) \
348
353
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kDebug , __func__) \
349
354
.stream()
350
- #define DLOG_INFO \
351
- if (trantor::Logger::logLevel() <= trantor::Logger::kInfo ) \
355
+ #define DLOG_INFO \
356
+ TRANTOR_IF_ (trantor::Logger::logLevel() <= trantor::Logger::kInfo) \
352
357
trantor::Logger(__FILE__, __LINE__).stream()
353
358
#define DLOG_WARN \
354
359
trantor::Logger (__FILE__, __LINE__, trantor::Logger::kWarn ).stream()
@@ -358,24 +363,27 @@ class TRANTOR_EXPORT RawLogger : public NonCopyable
358
363
trantor::Logger (__FILE__, __LINE__, trantor::Logger::kFatal ).stream()
359
364
360
365
#define DLOG_TRACE_IF (cond ) \
361
- if ((trantor::Logger::logLevel() <= trantor::Logger::kTrace ) && (cond)) \
366
+ TRANTOR_IF_ ((trantor::Logger::logLevel() <= trantor::Logger::kTrace) && \
367
+ (cond)) \
362
368
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kTrace , __func__) \
363
369
.stream()
364
370
#define DLOG_DEBUG_IF (cond ) \
365
- if ((trantor::Logger::logLevel() <= trantor::Logger::kDebug ) && (cond)) \
371
+ TRANTOR_IF_ ((trantor::Logger::logLevel() <= trantor::Logger::kDebug) && \
372
+ (cond)) \
366
373
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kDebug , __func__) \
367
374
.stream()
368
375
#define DLOG_INFO_IF (cond ) \
369
- if ((trantor::Logger::logLevel() <= trantor::Logger::kInfo ) && (cond)) \
376
+ TRANTOR_IF_ ((trantor::Logger::logLevel() <= trantor::Logger::kInfo) && \
377
+ (cond)) \
370
378
trantor::Logger(__FILE__, __LINE__).stream()
371
379
#define DLOG_WARN_IF (cond ) \
372
- if (cond) \
380
+ TRANTOR_IF_ (cond) \
373
381
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kWarn ).stream()
374
382
#define DLOG_ERROR_IF (cond ) \
375
- if (cond) \
383
+ TRANTOR_IF_ (cond) \
376
384
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kError ).stream()
377
385
#define DLOG_FATAL_IF (cond ) \
378
- if (cond) \
386
+ TRANTOR_IF_ (cond) \
379
387
trantor::Logger(__FILE__, __LINE__, trantor::Logger::kFatal ).stream()
380
388
#endif
381
389
0 commit comments