@@ -225,31 +225,31 @@ enum LogTriState
225
225
// USE LOG() INSTEAD
226
226
//
227
227
#ifndef _MSC_VER
228
- #define LOG_IMPL (str, ...) \
229
- { \
228
+ #define LOG_IMPL (str, ...) \
229
+ do { \
230
230
if (LOG_TARGET != nullptr ) \
231
231
{ \
232
232
fprintf (LOG_TARGET, LOG_TIMESTAMP_FMT LOG_FLF_FMT str " %s" LOG_TIMESTAMP_VAL LOG_FLF_VAL, __VA_ARGS__); \
233
233
fflush (LOG_TARGET); \
234
234
} \
235
- }
235
+ } while ( 0 )
236
236
#else
237
- #define LOG_IMPL (str, ...) \
238
- { \
237
+ #define LOG_IMPL (str, ...) \
238
+ do { \
239
239
if (LOG_TARGET != nullptr ) \
240
240
{ \
241
241
fprintf (LOG_TARGET, LOG_TIMESTAMP_FMT LOG_FLF_FMT str " %s" LOG_TIMESTAMP_VAL LOG_FLF_VAL " " , ##__VA_ARGS__); \
242
242
fflush (LOG_TARGET); \
243
243
} \
244
- }
244
+ } while ( 0 )
245
245
#endif
246
246
247
247
// INTERNAL, DO NOT USE
248
248
// USE LOG_TEE() INSTEAD
249
249
//
250
250
#ifndef _MSC_VER
251
- #define LOG_TEE_IMPL (str, ...) \
252
- { \
251
+ #define LOG_TEE_IMPL (str, ...) \
252
+ do { \
253
253
if (LOG_TARGET != nullptr ) \
254
254
{ \
255
255
fprintf (LOG_TARGET, LOG_TIMESTAMP_FMT LOG_FLF_FMT str " %s" LOG_TIMESTAMP_VAL LOG_FLF_VAL, __VA_ARGS__); \
@@ -260,10 +260,10 @@ enum LogTriState
260
260
fprintf (LOG_TEE_TARGET, LOG_TEE_TIMESTAMP_FMT LOG_TEE_FLF_FMT str " %s" LOG_TEE_TIMESTAMP_VAL LOG_TEE_FLF_VAL, __VA_ARGS__); \
261
261
fflush (LOG_TEE_TARGET); \
262
262
} \
263
- }
263
+ } while ( 0 )
264
264
#else
265
- #define LOG_TEE_IMPL (str, ...) \
266
- { \
265
+ #define LOG_TEE_IMPL (str, ...) \
266
+ do { \
267
267
if (LOG_TARGET != nullptr ) \
268
268
{ \
269
269
fprintf (LOG_TARGET, LOG_TIMESTAMP_FMT LOG_FLF_FMT str " %s" LOG_TIMESTAMP_VAL LOG_FLF_VAL " " , ##__VA_ARGS__); \
@@ -274,7 +274,7 @@ enum LogTriState
274
274
fprintf (LOG_TEE_TARGET, LOG_TEE_TIMESTAMP_FMT LOG_TEE_FLF_FMT str " %s" LOG_TEE_TIMESTAMP_VAL LOG_TEE_FLF_VAL " " , ##__VA_ARGS__); \
275
275
fflush (LOG_TEE_TARGET); \
276
276
} \
277
- }
277
+ } while ( 0 )
278
278
#endif
279
279
280
280
// The '\0' as a last argument, is a trick to bypass the silly
@@ -435,41 +435,41 @@ inline FILE *log_handler() { return log_handler1_impl(); }
435
435
inline void log_test ()
436
436
{
437
437
log_disable ();
438
- LOG (" 01 Hello World to nobody, because logs are disabled!\n " )
438
+ LOG (" 01 Hello World to nobody, because logs are disabled!\n " );
439
439
log_enable ();
440
- LOG (" 02 Hello World to default output, which is \" %s\" ( Yaaay, arguments! )!\n " , LOG_STRINGIZE (LOG_TARGET))
441
- LOG_TEE (" 03 Hello World to **both** default output and " LOG_TEE_TARGET_STRING " !\n " )
440
+ LOG (" 02 Hello World to default output, which is \" %s\" ( Yaaay, arguments! )!\n " , LOG_STRINGIZE (LOG_TARGET));
441
+ LOG_TEE (" 03 Hello World to **both** default output and " LOG_TEE_TARGET_STRING " !\n " );
442
442
log_set_target (stderr);
443
- LOG (" 04 Hello World to stderr!\n " )
444
- LOG_TEE (" 05 Hello World TEE with double printing to stderr prevented!\n " )
443
+ LOG (" 04 Hello World to stderr!\n " );
444
+ LOG_TEE (" 05 Hello World TEE with double printing to stderr prevented!\n " );
445
445
log_set_target (LOG_DEFAULT_FILE_NAME);
446
- LOG (" 06 Hello World to default log file!\n " )
446
+ LOG (" 06 Hello World to default log file!\n " );
447
447
log_set_target (stdout);
448
- LOG (" 07 Hello World to stdout!\n " )
448
+ LOG (" 07 Hello World to stdout!\n " );
449
449
log_set_target (LOG_DEFAULT_FILE_NAME);
450
- LOG (" 08 Hello World to default log file again!\n " )
450
+ LOG (" 08 Hello World to default log file again!\n " );
451
451
log_disable ();
452
- LOG (" 09 Hello World _1_ into the void!\n " )
452
+ LOG (" 09 Hello World _1_ into the void!\n " );
453
453
log_enable ();
454
- LOG (" 10 Hello World back from the void ( you should not see _1_ in the log or the output )!\n " )
454
+ LOG (" 10 Hello World back from the void ( you should not see _1_ in the log or the output )!\n " );
455
455
log_disable ();
456
456
log_set_target (" llama.anotherlog.log" );
457
- LOG (" 11 Hello World _2_ to nobody, new target was selected but logs are still disabled!\n " )
457
+ LOG (" 11 Hello World _2_ to nobody, new target was selected but logs are still disabled!\n " );
458
458
log_enable ();
459
- LOG (" 12 Hello World this time in a new file ( you should not see _2_ in the log or the output )?\n " )
459
+ LOG (" 12 Hello World this time in a new file ( you should not see _2_ in the log or the output )?\n " );
460
460
log_set_target (" llama.yetanotherlog.log" );
461
- LOG (" 13 Hello World this time in yet new file?\n " )
461
+ LOG (" 13 Hello World this time in yet new file?\n " );
462
462
log_set_target (log_filename_generator (" llama_autonamed" , " log" ));
463
- LOG (" 14 Hello World in log with generated filename!\n " )
463
+ LOG (" 14 Hello World in log with generated filename!\n " );
464
464
#ifdef _MSC_VER
465
- LOG_TEE (" 15 Hello msvc TEE without arguments\n " )
466
- LOG_TEE (" 16 Hello msvc TEE with (%d)(%s) arguments\n " , 1 , " test" )
467
- LOG_TEELN (" 17 Hello msvc TEELN without arguments\n " )
468
- LOG_TEELN (" 18 Hello msvc TEELN with (%d)(%s) arguments\n " , 1 , " test" )
469
- LOG (" 19 Hello msvc LOG without arguments\n " )
470
- LOG (" 20 Hello msvc LOG with (%d)(%s) arguments\n " , 1 , " test" )
471
- LOGLN (" 21 Hello msvc LOGLN without arguments\n " )
472
- LOGLN (" 22 Hello msvc LOGLN with (%d)(%s) arguments\n " , 1 , " test" )
465
+ LOG_TEE (" 15 Hello msvc TEE without arguments\n " );
466
+ LOG_TEE (" 16 Hello msvc TEE with (%d)(%s) arguments\n " , 1 , " test" );
467
+ LOG_TEELN (" 17 Hello msvc TEELN without arguments\n " );
468
+ LOG_TEELN (" 18 Hello msvc TEELN with (%d)(%s) arguments\n " , 1 , " test" );
469
+ LOG (" 19 Hello msvc LOG without arguments\n " );
470
+ LOG (" 20 Hello msvc LOG with (%d)(%s) arguments\n " , 1 , " test" );
471
+ LOGLN (" 21 Hello msvc LOGLN without arguments\n " );
472
+ LOGLN (" 22 Hello msvc LOGLN with (%d)(%s) arguments\n " , 1 , " test" );
473
473
#endif
474
474
}
475
475
@@ -542,7 +542,7 @@ inline void log_dump_cmdline_impl(int argc, char **argv)
542
542
buf << " " << argv[i];
543
543
}
544
544
}
545
- LOGLN (" Cmd:%s" , buf.str ().c_str ())
545
+ LOGLN (" Cmd:%s" , buf.str ().c_str ());
546
546
}
547
547
548
548
#define log_tostr (var ) log_var_to_string_impl(var).c_str()
@@ -620,10 +620,10 @@ inline std::string log_var_to_string_impl(const std::vector<int> & var)
620
620
#define LOGLN (...) // dummy stub
621
621
622
622
#undef LOG_TEE
623
- #define LOG_TEE (...) fprintf(stderr, __VA_ARGS__); // convert to normal fprintf
623
+ #define LOG_TEE (...) fprintf(stderr, __VA_ARGS__) // convert to normal fprintf
624
624
625
625
#undef LOG_TEELN
626
- #define LOG_TEELN (...) fprintf(stderr, __VA_ARGS__); // convert to normal fprintf
626
+ #define LOG_TEELN (...) fprintf(stderr, __VA_ARGS__) // convert to normal fprintf
627
627
628
628
#undef LOG_DISABLE
629
629
#define LOG_DISABLE () // dummy stub
0 commit comments