1 /* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
2 /* See LICENSE for licensing information */
8 * \brief Headers for logging functions.
12 #define LOG_H_ID "$Id$"
14 #include "../common/compat.h"
18 #define LOG_WARN LOG_WARNING
19 #if LOG_DEBUG < LOG_ERR
20 #error "Your syslog.h thinks high numbers are more important. We aren't prepared to deal with that."
23 /* XXXX Note: The code was originally written to refer to severities,
24 * with 0 being the least severe; while syslog's logging code refers to
25 * priorities, with 0 being the most important. Thus, all our comparisons
26 * needed to be reversed when we added syslog support.
28 * The upshot of this is that comments about log levels may be messed
29 * up: for "maximum severity" read "most severe" and "numerically
33 /** Debug-level severity: for hyper-verbose messages of no interest to
34 * anybody but developers. */
36 /** Info-level severity: for messages that appear frequently during normal
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.
44 /** Warn-level severity: for messages that only appear when something has gone
47 /** Error-level severity: for messages that only appear when something has gone
48 * very wrong, and the Tor process can no longer proceed. */
52 typedef void (*log_callback
)(int severity
, const char *msg
);
54 int parse_log_level(const char *level
);
55 const char *log_level_to_string(int level
);
56 void add_stream_log(int severityMin
, int severityMax
, const char *name
, FILE *stream
);
57 int add_file_log(int severityMin
, int severityMax
, const char *filename
);
59 int add_syslog_log(int loglevelMin
, int loglevelMax
);
61 int add_callback_log(int loglevelMin
, int loglevelMax
, log_callback cb
);
62 int get_min_log_level(void);
63 void switch_logs_debug(void);
64 void close_logs(void);
65 void reset_logs(void);
66 void add_temp_log(void);
67 void close_temp_logs(void);
68 void mark_logs_temp(void);
70 /* Outputs a message to stdout */
71 void _log(int severity
, const char *format
, ...) CHECK_PRINTF(2,3);
74 void _log_fn(int severity
, const char *funcname
, const char *format
, ...)
76 /** Log a message at level <b>severity</b>, using a pretty-printed version
77 * of the current function name. */
78 #define log_fn(severity, args...) \
79 _log_fn(severity, __PRETTY_FUNCTION__, args)
80 #elif defined(_MSC_VER) && _MSC_VER < 1300
81 /* MSVC 6 and earlier don't have __FUNCTION__, or even __LINE__. */
84 /* We don't have GCC's varargs macros, so use a global variable to pass the
85 * function name to log_fn */
86 extern const char *_log_fn_function_name
;
87 void _log_fn(int severity
, const char *format
, ...);
88 /* We abuse the comma operator here, since we can't use the standard
89 * do {...} while (0) trick to wrap this macro, since the macro can't take
91 #define log_fn (_log_fn_function_name=__FUNCTION__),_log_fn
93 #define log _log /* hack it so we don't conflict with log() as much */