log.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #else
  11. #define LOG_DEBUG 0
  12. #define LOG_INFO 1
  13. #define LOG_NOTICE 2
  14. #define LOG_WARNING 3
  15. #define LOG_ERR 4
  16. #define LOG_CRIT 5
  17. #define LOG_ALERT 6
  18. #define LOG_EMERG 7
  19. #endif
  20. /* magic to make GCC check for proper format strings. */
  21. #ifdef __GNUC__
  22. #define CHECK_PRINTF(formatIdx, firstArg) \
  23. __attribute__ ((format (printf, formatIdx, firstArg)))
  24. #else
  25. #define CHECK_PRINTF(formatIdx, firstArg)
  26. #endif
  27. void log_set_severity(int severity);
  28. void add_stream_log(int loglevel, const char *name, FILE *stream);
  29. void add_file_log(int severity, const char *filename);
  30. void close_logs();
  31. void reset_logs();
  32. /* Outputs a message to stdout */
  33. void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
  34. #ifdef __GNUC__
  35. void _log_fn(int severity, const char *funcname, const char *format, ...)
  36. CHECK_PRINTF(3,4);
  37. #define log_fn(severity, args...) \
  38. _log_fn(severity, __PRETTY_FUNCTION__, args)
  39. #else
  40. #define log_fn _log
  41. #endif
  42. #define log _log /* hack it so we don't conflict with log() as much */
  43. # define __LOG_H
  44. #endif