diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-04-01 02:37:40 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-04-01 02:37:40 +0000 |
commit | efe9ca659a3d53b388124e2dd777d29e4914e1fb (patch) | |
tree | 9b61f8a09b38909d78536d4af118afe3ea718150 /src/common | |
parent | 837d7dff69c9844e40d9cdd440906e2dbe97106c (diff) | |
download | tor-efe9ca659a3d53b388124e2dd777d29e4914e1fb.tar.gz tor-efe9ca659a3d53b388124e2dd777d29e4914e1fb.zip |
Use recent libevent features when possible
svn:r3940
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/log.c | 34 | ||||
-rw-r--r-- | src/common/log.h | 1 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/common/log.c b/src/common/log.c index c134fe4ee0..94a683fb96 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -17,6 +17,12 @@ const char log_c_id[] = "$Id$"; #include "./util.h" #include "./log.h" +#ifdef HAVE_EVENT_H +#include <event.h> +#else +#error "Tor requires libevent to build." +#endif + #define TRUNCATED_STR "[...truncated]" #define TRUNCATED_STR_LEN 14 @@ -475,3 +481,31 @@ void switch_logs_debug(void) } } +#ifdef HAVE_EVENT_SET_LOG_CALLBACK +void libevent_logging_callback(int severity, const char *msg) +{ + switch (severity) { + case _EVENT_LOG_DEBUG: + log(LOG_DEBUG, "Message from libevent: %s", msg); + break; + case _EVENT_LOG_MSG: + log(LOG_INFO, "Message from libevent: %s", msg); + break; + case _EVENT_LOG_WARN: + log(LOG_WARN, "Warning from libevent: %s", msg); + break; + case _EVENT_LOG_ERR: + log(LOG_ERR, "Error from libevent: %s", msg); + break; + default: + log(LOG_WARN, "Message [%d] from libevent: %s", severity, msg); + break; + } +} +void configure_libevent_logging(void) +{ + event_set_log_callback(libevent_logging_callback); +} +#else +void configure_libevent_logging(void) {} +#endif diff --git a/src/common/log.h b/src/common/log.h index d362549e9c..af90f6d90a 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -66,6 +66,7 @@ void reset_logs(void); void add_temp_log(void); void close_temp_logs(void); void mark_logs_temp(void); +void configure_libevent_logging(void); /* Outputs a message to stdout */ void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3); |