log.h 790 B

1234567891011121314151617181920212223242526272829303132333435
  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. void log_set_severity(int severity);
  17. /* Outputs a message to stdout and also logs the same message using syslog. */
  18. void log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
  19. #ifdef __GNUC__
  20. void _log_fn(int severity, const char *funcname, const char *format, ...)
  21. CHECK_PRINTF(3,4);
  22. #define log_fn(severity, args...) \
  23. _log_fn(severity, __PRETTY_FUNCTION__, args)
  24. #else
  25. #define log_fn log
  26. #endif
  27. # define __LOG_H
  28. #endif