Possible fix for broken country settings in ExcludeExitNodes.
[tor/rransom.git] / src / common / log.h
blob66f5ee39bfdd6dce1a675bde4ba8a78dcbc378ba
1 /* Copyright (c) 2001, Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2008, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file log.h
10 * \brief Headers for log.c
11 **/
13 #ifndef _TOR_LOG_H
15 #include "compat.h"
17 #ifdef HAVE_SYSLOG_H
18 #include <syslog.h>
19 #define LOG_WARN LOG_WARNING
20 #if LOG_DEBUG < LOG_ERR
21 #error "Your syslog.h thinks high numbers are more important. " \
22 "We aren't prepared to deal with that."
23 #endif
24 #else
25 /* Note: Syslog's logging code refers to priorities, with 0 being the most
26 * important. Thus, all our comparisons needed to be reversed when we added
27 * syslog support.
29 * The upshot of this is that comments about log levels may be messed up: for
30 * "maximum severity" read "most severe" and "numerically *lowest* severity".
33 /** Debug-level severity: for hyper-verbose messages of no interest to
34 * anybody but developers. */
35 #define LOG_DEBUG 7
36 /** Info-level severity: for messages that appear frequently during normal
37 * operation. */
38 #define LOG_INFO 6
39 /** Notice-level severity: for messages that appear infrequently
40 * during normal operation; that the user will probably care about;
41 * and that are not errors.
43 #define LOG_NOTICE 5
44 /** Warn-level severity: for messages that only appear when something has gone
45 * wrong. */
46 #define LOG_WARN 4
47 /** Error-level severity: for messages that only appear when something has gone
48 * very wrong, and the Tor process can no longer proceed. */
49 #define LOG_ERR 3
50 #endif
52 /* Logging domains */
54 /** Catch-all for miscellaneous events and fatal errors. */
55 #define LD_GENERAL (1u<<0)
56 /** The cryptography subsytem. */
57 #define LD_CRYPTO (1u<<1)
58 /** Networking. */
59 #define LD_NET (1u<<2)
60 /** Parsing and acting on our configuration. */
61 #define LD_CONFIG (1u<<3)
62 /** Reading and writing from the filesystem. */
63 #define LD_FS (1u<<4)
64 /** Other servers' (non)compliance with the Tor protocol. */
65 #define LD_PROTOCOL (1u<<5)
66 /** Memory management. */
67 #define LD_MM (1u<<6)
68 /** HTTP implementation. */
69 #define LD_HTTP (1u<<7)
70 /** Application (socks) requests. */
71 #define LD_APP (1u<<8)
72 /** Communication via the controller protocol. */
73 #define LD_CONTROL (1u<<9)
74 /** Building, using, and managing circuits. */
75 #define LD_CIRC (1u<<10)
76 /** Hidden services. */
77 #define LD_REND (1u<<11)
78 /** Internal errors in this Tor process. */
79 #define LD_BUG (1u<<12)
80 /** Learning and using information about Tor servers. */
81 #define LD_DIR (1u<<13)
82 /** Learning and using information about Tor servers. */
83 #define LD_DIRSERV (1u<<14)
84 /** Onion routing protocol. */
85 #define LD_OR (1u<<15)
86 /** Generic edge-connection functionality. */
87 #define LD_EDGE (1u<<16)
88 #define LD_EXIT LD_EDGE
89 /** Bandwidth accounting. */
90 #define LD_ACCT (1u<<17)
91 /** Router history */
92 #define LD_HIST (1u<<18)
94 /** Number of logging domains in the code. */
95 #define N_LOGGING_DOMAINS 19
97 typedef uint32_t log_domain_mask_t;
99 /** Configures which severities are logged for each logging domain for a given
100 * log target. */
101 typedef struct log_severity_list_t {
102 /** For each log severity, a bitmask of which domains a given logger is
103 * logging. */
104 log_domain_mask_t masks[LOG_DEBUG-LOG_ERR+1];
105 } log_severity_list_t;
107 #ifdef LOG_PRIVATE
108 /** Given a severity, yields an index into log_severity_list_t.masks to use
109 * for that severity. */
110 #define SEVERITY_MASK_IDX(sev) ((sev) - LOG_ERR)
111 #endif
113 /** Callback type used for add_callback_log. */
114 typedef void (*log_callback)(int severity, uint32_t domain, const char *msg);
116 void init_logging(void);
117 int parse_log_level(const char *level);
118 const char *log_level_to_string(int level);
119 int parse_log_severity_config(const char **cfg,
120 log_severity_list_t *severity_out);
121 void set_log_severity_config(int minSeverity, int maxSeverity,
122 log_severity_list_t *severity_out);
123 void add_stream_log(const log_severity_list_t *severity, const char *name,
124 int fd);
125 int add_file_log(const log_severity_list_t *severity, const char *filename);
126 #ifdef HAVE_SYSLOG_H
127 int add_syslog_log(const log_severity_list_t *severity);
128 #endif
129 int add_callback_log(const log_severity_list_t *severity, log_callback cb);
130 int get_min_log_level(void);
131 void switch_logs_debug(void);
132 void logs_free_all(void);
133 void add_temp_log(int min_severity);
134 void close_temp_logs(void);
135 void rollback_log_changes(void);
136 void mark_logs_temp(void);
137 void configure_libevent_logging(void);
138 void suppress_libevent_log_msg(const char *msg);
139 void change_callback_log_severity(int loglevelMin, int loglevelMax,
140 log_callback cb);
141 void log_set_application_name(const char *name);
143 /* Outputs a message to stdout */
144 void _log(int severity, log_domain_mask_t domain, const char *format, ...)
145 CHECK_PRINTF(3,4);
146 #define log _log /* hack it so we don't conflict with log() as much */
148 #ifdef __GNUC__
149 extern int _log_global_min_severity;
151 void _log_fn(int severity, log_domain_mask_t domain,
152 const char *funcname, const char *format, ...)
153 CHECK_PRINTF(4,5);
154 /** Log a message at level <b>severity</b>, using a pretty-printed version
155 * of the current function name. */
156 #define log_fn(severity, domain, args...) \
157 _log_fn(severity, domain, __PRETTY_FUNCTION__, args)
158 #define log_debug(domain, args...) \
159 STMT_BEGIN \
160 if (PREDICT_UNLIKELY(_log_global_min_severity == LOG_DEBUG)) \
161 _log_fn(LOG_DEBUG, domain, __PRETTY_FUNCTION__, args); \
162 STMT_END
163 #define log_info(domain, args...) \
164 _log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args)
165 #define log_notice(domain, args...) \
166 _log_fn(LOG_NOTICE, domain, __PRETTY_FUNCTION__, args)
167 #define log_warn(domain, args...) \
168 _log_fn(LOG_WARN, domain, __PRETTY_FUNCTION__, args)
169 #define log_err(domain, args...) \
170 _log_fn(LOG_ERR, domain, __PRETTY_FUNCTION__, args)
172 #else /* ! defined(__GNUC__) */
174 void _log_fn(int severity, log_domain_mask_t domain, const char *format, ...);
175 void _log_debug(log_domain_mask_t domain, const char *format, ...);
176 void _log_info(log_domain_mask_t domain, const char *format, ...);
177 void _log_notice(log_domain_mask_t domain, const char *format, ...);
178 void _log_warn(log_domain_mask_t domain, const char *format, ...);
179 void _log_err(log_domain_mask_t domain, const char *format, ...);
181 #if defined(_MSC_VER) && _MSC_VER < 1300
182 /* MSVC 6 and earlier don't have __func__, or even __LINE__. */
183 #define log_fn _log_fn
184 #define log_debug _log_debug
185 #define log_info _log_info
186 #define log_notice _log_notice
187 #define log_warn _log_warn
188 #define log_err _log_err
189 #else
190 /* We don't have GCC's varargs macros, so use a global variable to pass the
191 * function name to log_fn */
192 extern const char *_log_fn_function_name;
193 /* We abuse the comma operator here, since we can't use the standard
194 * do {...} while (0) trick to wrap this macro, since the macro can't take
195 * arguments. */
196 #define log_fn (_log_fn_function_name=__func__),_log_fn
197 #define log_debug (_log_fn_function_name=__func__),_log_debug
198 #define log_info (_log_fn_function_name=__func__),_log_info
199 #define log_notice (_log_fn_function_name=__func__),_log_notice
200 #define log_warn (_log_fn_function_name=__func__),_log_warn
201 #define log_err (_log_fn_function_name=__func__),_log_err
202 #endif
204 #endif /* !GNUC */
206 # define _TOR_LOG_H
207 #endif