log.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * log.h
  3. * Logging facilities.
  4. *
  5. * Matej Pfajfar <mp292@cam.ac.uk>
  6. */
  7. #ifndef __LOG_H
  8. #ifdef HAVE_SYSLOG_H
  9. #include <syslog.h>
  10. #define LOG_WARN LOG_WARNING
  11. #else
  12. #define LOG_DEBUG 0
  13. #define LOG_INFO 1
  14. #define LOG_WARN 3
  15. #define LOG_ERR 4
  16. #endif
  17. /* magic to make GCC check for proper format strings. */
  18. #ifdef __GNUC__
  19. #define CHECK_PRINTF(formatIdx, firstArg) \
  20. __attribute__ ((format (printf, formatIdx, firstArg)))
  21. #else
  22. #define CHECK_PRINTF(formatIdx, firstArg)
  23. #endif
  24. void log_set_severity(int severity);
  25. void add_stream_log(int loglevel, const char *name, FILE *stream);
  26. void add_file_log(int severity, const char *filename);
  27. void close_logs();
  28. void reset_logs();
  29. /* Outputs a message to stdout */
  30. void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
  31. #ifdef __GNUC__
  32. void _log_fn(int severity, const char *funcname, const char *format, ...)
  33. CHECK_PRINTF(3,4);
  34. #define log_fn(severity, args...) \
  35. _log_fn(severity, __PRETTY_FUNCTION__, args)
  36. #else
  37. #define log_fn _log
  38. #endif
  39. #define log _log /* hack it so we don't conflict with log() as much */
  40. # define __LOG_H
  41. #endif