log.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. typedef void (*log_callback)(int severity, const char *msg);
  50. int parse_log_level(const char *level);
  51. const char *log_level_to_string(int level);
  52. void add_stream_log(int severityMin, int severityMax, const char *name, FILE *stream);
  53. int add_file_log(int severityMin, int severityMax, const char *filename);
  54. #ifdef HAVE_SYSLOG_H
  55. int add_syslog_log(int loglevelMin, int loglevelMax);
  56. #endif
  57. int add_callback_log(int loglevelMin, int loglevelMax, log_callback cb);
  58. int get_min_log_level(void);
  59. void close_logs(void);
  60. void reset_logs(void);
  61. void add_temp_log(void);
  62. void close_temp_logs(void);
  63. void mark_logs_temp(void);
  64. /* Outputs a message to stdout */
  65. void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
  66. #ifdef __GNUC__
  67. void _log_fn(int severity, const char *funcname, const char *format, ...)
  68. CHECK_PRINTF(3,4);
  69. /** Log a message at level <b>severity</b>, using a pretty-printed version
  70. * of the current function name. */
  71. #define log_fn(severity, args...) \
  72. _log_fn(severity, __PRETTY_FUNCTION__, args)
  73. #else
  74. #define log_fn _log
  75. #endif
  76. #define log _log /* hack it so we don't conflict with log() as much */
  77. # define __LOG_H
  78. #endif
  79. /*
  80. Local Variables:
  81. mode:c
  82. indent-tabs-mode:nil
  83. c-basic-offset:2
  84. End:
  85. */