log.h 752 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * log.h
  3. * Logging facilities.
  4. *
  5. * Matej Pfajfar <mp292@cam.ac.uk>
  6. */
  7. #ifndef __LOG_H
  8. #include <syslog.h>
  9. /* magic to make GCC check for proper format strings. */
  10. #ifdef __GNUC__
  11. #define CHECK_PRINTF(formatIdx, firstArg) \
  12. __attribute__ ((format (printf, formatIdx, firstArg)))
  13. #else
  14. #define CHECK_PRINTF(formatIdx, firstArg)
  15. #endif
  16. /* Outputs a message to stdout and also logs the same message using syslog. */
  17. void log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
  18. #ifdef __GNUC__
  19. void _log_fn(int severity, const char *funcname, const char *format, ...)
  20. CHECK_PRINTF(3,4);
  21. #define log_fn(severity, args...) \
  22. _log_fn(severity, __PRETTY_FUNCTION__, args)
  23. #else
  24. #define log_fn log
  25. #endif
  26. # define __LOG_H
  27. #endif