summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-12-16 13:58:56 -0500
committerNick Mathewson <nickm@torproject.org>2010-12-16 13:58:56 -0500
commite30a82f11829e3dc2cf1add253c768fa144db494 (patch)
tree27fc34bba15b8e56b1ef685f8f5d29abdb9ee25c
parentb8b8aa560c038c6f0c22a574d99d314a1f4a3b7a (diff)
downloadlibevent-e30a82f11829e3dc2cf1add253c768fa144db494.tar.gz
Add event_enable_debug_logging() to control use of debug logs
Previously, debug logs were turned on if you built with -DUSE_DEBUG and off otherwise. This make builds with -DUSE_DEBUG hideously slow and other builds unable to get debug logs. This is based off a patch by Ralph Castain from October. It tries a little harder to avoid needless function calls, it doesn't require stdbool, and makes the controlling parameter a mask rather than a boolean so that we can later support enabling only the debugging messages for the parts of Libevent you're trying to debug.
-rw-r--r--include/event2/event.h16
-rw-r--r--log-internal.h27
-rw-r--r--log.c19
3 files changed, 59 insertions, 3 deletions
diff --git a/include/event2/event.h b/include/event2/event.h
index 4b05b325..f71d0844 100644
--- a/include/event2/event.h
+++ b/include/event2/event.h
@@ -313,6 +313,22 @@ void event_set_log_callback(event_log_cb cb);
typedef void (*event_fatal_cb)(int err);
void event_set_fatal_callback(event_fatal_cb cb);
+#define EVENT_DBG_ALL 0xffffffffu
+
+/**
+ Turn on debugging logs and have them sent to the default log handler.
+
+ This is a global setting; you must call this before any calls that create an
+ event-base.
+
+ Debug logs are verbose.
+
+ @param which Controls which debug messages are turned on. This option is
+ unused for now; for forward compatibility, you must pass in the constant
+ "EVENT_DBG_ALL"
+ */
+void event_enable_debug_logging(ev_uint32_t which);
+
/**
Associate a different event base with an event.
diff --git a/log-internal.h b/log-internal.h
index c1905aea..e3c6d564 100644
--- a/log-internal.h
+++ b/log-internal.h
@@ -39,6 +39,23 @@
#define _EVENT_ERR_ABORT ((int)0xdeaddead)
+#define USE_GLOBAL_FOR_DEBUG_LOGGING
+
+#if !defined(_EVENT_DISABLE_DEBUG_MODE) || defined(USE_DEBUG)
+#define EVENT_DEBUG_LOGGING_ENABLED
+#endif
+
+#ifdef EVENT_DEBUG_LOGGING_ENABLED
+#ifdef USE_GLOBAL_FOR_DEBUG_LOGGING
+extern ev_uint32_t _event_debug_logging_mask;
+#define _event_debug_get_logging_mask() (_event_debug_logging_mask)
+#else
+ev_uint32_t _event_debug_get_logging_mask(void);
+#endif
+#else
+#define _event_debug_get_logging_mask() (0)
+#endif
+
void event_err(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
void event_warn(const char *fmt, ...) EV_CHECK_FMT(1,2);
void event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(3,4) EV_NORETURN;
@@ -48,10 +65,14 @@ void event_warnx(const char *fmt, ...) EV_CHECK_FMT(1,2);
void event_msgx(const char *fmt, ...) EV_CHECK_FMT(1,2);
void _event_debugx(const char *fmt, ...) EV_CHECK_FMT(1,2);
-#ifdef USE_DEBUG
-#define event_debug(x) _event_debugx x
+#ifdef EVENT_DEBUG_LOGGING_ENABLED
+#define event_debug(x) do { \
+ if (_event_debug_get_logging_mask()) { \
+ _event_debugx x; \
+ } \
+ } while (0)
#else
-#define event_debug(x) do {;} while (0)
+#define event_debug(x) ((void)0)
#endif
#undef EV_CHECK_FMT
diff --git a/log.c b/log.c
index f0cd4320..79eaae71 100644
--- a/log.c
+++ b/log.c
@@ -63,6 +63,25 @@ static void event_exit(int errcode) EV_NORETURN;
static event_fatal_cb fatal_fn = NULL;
+#ifdef EVENT_DEBUG_LOGGING_ENABLED
+#ifdef USE_DEBUG
+#define DEFAULT_MASK EVENT_DBG_ALL
+#else
+#define DEFAULT_MASK 0
+#endif
+
+#ifdef USE_GLOBAL_FOR_DEBUG_LOGGING
+ev_uint32_t _event_debug_logging_mask = DEFAULT_MASK;
+#else
+static ev_uint32_t _event_debug_logging_mask = DEFAULT_MASK;
+ev_uint32_t
+_event_debug_get_logging_mask(void)
+{
+ return _event_debug_logging_mask;
+}
+#endif
+#endif /* EVENT_DEBUG_LOGGING_ENABLED */
+
void
event_set_fatal_callback(event_fatal_cb cb)
{