args_eval.c 972 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <signal.h>
  2. #include <stdlib.h>
  3. #define ZF_LOG_LEVEL ZF_LOG_INFO
  4. #include <zf_log.h>
  5. static int call_exit()
  6. {
  7. exit(1);
  8. }
  9. int main(int argc, char *argv[])
  10. {
  11. (void)argc; (void)argv;
  12. /* Current log level is set to ZF_LOG_INFO by defining ZF_LOG_LEVEL
  13. * before zf_log.h include. All log messages below INFO level will be
  14. * compiled out.
  15. */
  16. ZF_LOGV("Argument of this VERBOSE message will not be evaluated: %i",
  17. call_exit());
  18. ZF_LOGI("So you will see that INFO message");
  19. /* Output log level is set to WARN and then to INFO. Argument of INFO log
  20. * statement will be evaluated only once (after setting output log level to
  21. * INFO).
  22. */
  23. zf_log_set_output_level(ZF_LOG_WARN);
  24. int count = 0;
  25. for (int i = 2; 0 < i--;)
  26. {
  27. ZF_LOGI("Argument of this INFO message will be evaluated only once: %i",
  28. ++count);
  29. zf_log_set_output_level(ZF_LOG_INFO);
  30. }
  31. if (1 != count)
  32. {
  33. abort();
  34. }
  35. ZF_LOGI("And you will see that INFO message");
  36. return 0;
  37. }