Forward port changelog
[tor.git] / src / common / log.h
blobd362549e9c940b1de68d04c7aeac819cad913aeb
1 /* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
2 /* See LICENSE for licensing information */
3 /* $Id$ */
5 /**
6 * \file log.h
8 * \brief Headers for logging functions.
9 **/
11 #ifndef __LOG_H
12 #define LOG_H_ID "$Id$"
14 #include "../common/compat.h"
16 #ifdef HAVE_SYSLOG_H
17 #include <syslog.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."
21 #endif
22 #else
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
30 * *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 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);
58 #ifdef HAVE_SYSLOG_H
59 int add_syslog_log(int loglevelMin, int loglevelMax);
60 #endif
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);
73 #ifdef __GNUC__
74 void _log_fn(int severity, const char *funcname, const char *format, ...)
75 CHECK_PRINTF(3,4);
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__. */
82 #define log_fn _log
83 #else
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
90 * arguments. */
91 #define log_fn (_log_fn_function_name=__FUNCTION__),_log_fn
92 #endif
93 #define log _log /* hack it so we don't conflict with log() as much */
95 # define __LOG_H
96 #endif