log.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_NOTICE 2
  12. #define LOG_WARN 3
  13. #define LOG_ERR 4
  14. #endif
  15. /* magic to make GCC check for proper format strings. */
  16. #ifdef __GNUC__
  17. #define CHECK_PRINTF(formatIdx, firstArg) \
  18. __attribute__ ((format (printf, formatIdx, firstArg)))
  19. #else
  20. #define CHECK_PRINTF(formatIdx, firstArg)
  21. #endif
  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
  39. /*
  40. Local Variables:
  41. mode:c
  42. indent-tabs-mode:nil
  43. c-basic-offset:2
  44. End:
  45. */