log.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
  2. /* See LICENSE for licensing information */
  3. /* $Id$ */
  4. /**
  5. * /file log.h
  6. *
  7. * /brief Headers for logging functions.
  8. **/
  9. #ifndef __LOG_H
  10. /**
  11. * \file log.h
  12. * \brief Headers for log.c
  13. */
  14. #include "../common/compat.h"
  15. #ifdef HAVE_SYSLOG_H
  16. #include <syslog.h>
  17. #define LOG_WARN LOG_WARNING
  18. #if LOG_DEBUG < LOG_ERR
  19. #error "Your syslog.h thinks high numbers are more important. We aren't prepared to deal with that."
  20. #endif
  21. #else
  22. /* XXXX Note: The code was originally written to refer to severities,
  23. * with 0 being the least severe; while syslog's logging code refers to
  24. * priorities, with 0 being the most important. Thus, all our comparisons
  25. * needed to be reversed when we added syslog support.
  26. *
  27. * The upshot of this is that comments about log levels may be messed
  28. * up: for "maximum severity" read "most severe" and "numerically
  29. * *lowest* severity".
  30. */
  31. /** Debug-level severity: for hyper-verbose messages of no interest to
  32. * anybody but developers. */
  33. #define LOG_DEBUG 7
  34. /** Info-level severity: for messages that appear frequently during normal
  35. * operation. */
  36. #define LOG_INFO 6
  37. /** Notice-level severity: for messages that appear infrequently
  38. * during normal operation; that the user will probably care about;
  39. * and that are not errors.
  40. */
  41. #define LOG_NOTICE 5
  42. /** Warn-level severity: for messages that only appear when something has gone
  43. * wrong. */
  44. #define LOG_WARN 4
  45. /** Error-level severity: for messages that only appear when something has gone
  46. * very wrong, and the Tor process can no longer proceed. */
  47. #define LOG_ERR 3
  48. #endif
  49. int parse_log_level(const char *level);
  50. void add_stream_log(int severityMin, int severityMax, const char *name, FILE *stream);
  51. int add_file_log(int severityMin, int severityMax, const char *filename);
  52. #ifdef HAVE_SYSLOG_H
  53. int add_syslog_log(int loglevelMin, int loglevelMax);
  54. #endif
  55. int get_min_log_level(void);
  56. void close_logs(void);
  57. void reset_logs(void);
  58. void add_temp_log(void);
  59. void close_temp_logs(void);
  60. void mark_logs_temp(void);
  61. /* Outputs a message to stdout */
  62. void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
  63. #ifdef __GNUC__
  64. void _log_fn(int severity, const char *funcname, const char *format, ...)
  65. CHECK_PRINTF(3,4);
  66. /** Log a message at level <b>severity</b>, using a pretty-printed version
  67. * of the current function name. */
  68. #define log_fn(severity, args...) \
  69. _log_fn(severity, __PRETTY_FUNCTION__, args)
  70. #else
  71. #define log_fn _log
  72. #endif
  73. #define log _log /* hack it so we don't conflict with log() as much */
  74. # define __LOG_H
  75. #endif
  76. /*
  77. Local Variables:
  78. mode:c
  79. indent-tabs-mode:nil
  80. c-basic-offset:2
  81. End:
  82. */