log.h 1.1 KB

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