Merge branch '21_evdns_log_debug'

This commit is contained in:
Nick Mathewson 2013-06-10 10:47:35 -04:00
commit 36ab0721be
4 changed files with 29 additions and 40 deletions

37
evdns.c
View File

@ -119,9 +119,9 @@
#include <netinet/in6.h>
#endif
#define EVDNS_LOG_DEBUG 0
#define EVDNS_LOG_WARN 1
#define EVDNS_LOG_MSG 2
#define EVDNS_LOG_DEBUG EVENT_LOG_DEBUG
#define EVDNS_LOG_WARN EVENT_LOG_WARN
#define EVDNS_LOG_MSG EVENT_LOG_MSG
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 255
@ -432,17 +432,6 @@ static int strtoint(const char *const str);
EVLOCK_ASSERT_LOCKED((base)->lock)
#endif
static void
default_evdns_log_fn(int warning, const char *buf)
{
if (warning == EVDNS_LOG_WARN)
event_warnx("[evdns] %s", buf);
else if (warning == EVDNS_LOG_MSG)
event_msgx("[evdns] %s", buf);
else
event_debug(("[evdns] %s", buf));
}
static evdns_debug_log_fn_type evdns_log_fn = NULL;
void
@ -457,25 +446,21 @@ evdns_set_log_fn(evdns_debug_log_fn_type fn)
#define EVDNS_LOG_CHECK
#endif
static void evdns_log_(int warn, const char *fmt, ...) EVDNS_LOG_CHECK;
static void evdns_log_(int severity, const char *fmt, ...) EVDNS_LOG_CHECK;
static void
evdns_log_(int warn, const char *fmt, ...)
evdns_log_(int severity, const char *fmt, ...)
{
va_list args;
char buf[512];
if (!evdns_log_fn)
return;
va_start(args,fmt);
evutil_vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
if (evdns_log_fn) {
if (warn == EVDNS_LOG_MSG)
warn = EVDNS_LOG_WARN;
evdns_log_fn(warn, buf);
char buf[512];
int is_warn = (severity == EVDNS_LOG_WARN);
evutil_vsnprintf(buf, sizeof(buf), fmt, args);
evdns_log_fn(is_warn, buf);
} else {
default_evdns_log_fn(warn, buf);
event_logv_(severity, NULL, fmt, args);
}
va_end(args);
}
#define log evdns_log_

View File

@ -65,6 +65,9 @@ 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);
void event_logv_(int severity, const char *errstr, const char *fmt, va_list ap)
EV_CHECK_FMT(3,0);
#ifdef EVENT_DEBUG_LOGGING_ENABLED
#define event_debug(x) do { \
if (event_debug_get_logging_mask_()) { \

25
log.c
View File

@ -57,8 +57,6 @@
#include "log-internal.h"
static void warn_helper_(int severity, const char *errstr, const char *fmt,
va_list ap);
static void event_log(int severity, const char *msg);
static void event_exit(int errcode) EV_NORETURN;
@ -115,7 +113,7 @@ event_err(int eval, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
warn_helper_(EVENT_LOG_ERR, strerror(errno), fmt, ap);
event_logv_(EVENT_LOG_ERR, strerror(errno), fmt, ap);
va_end(ap);
event_exit(eval);
}
@ -126,7 +124,7 @@ event_warn(const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
warn_helper_(EVENT_LOG_WARN, strerror(errno), fmt, ap);
event_logv_(EVENT_LOG_WARN, strerror(errno), fmt, ap);
va_end(ap);
}
@ -137,7 +135,7 @@ event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...)
int err = evutil_socket_geterror(sock);
va_start(ap, fmt);
warn_helper_(EVENT_LOG_ERR, evutil_socket_error_to_string(err), fmt, ap);
event_logv_(EVENT_LOG_ERR, evutil_socket_error_to_string(err), fmt, ap);
va_end(ap);
event_exit(eval);
}
@ -149,7 +147,7 @@ event_sock_warn(evutil_socket_t sock, const char *fmt, ...)
int err = evutil_socket_geterror(sock);
va_start(ap, fmt);
warn_helper_(EVENT_LOG_WARN, evutil_socket_error_to_string(err), fmt, ap);
event_logv_(EVENT_LOG_WARN, evutil_socket_error_to_string(err), fmt, ap);
va_end(ap);
}
@ -159,7 +157,7 @@ event_errx(int eval, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
warn_helper_(EVENT_LOG_ERR, NULL, fmt, ap);
event_logv_(EVENT_LOG_ERR, NULL, fmt, ap);
va_end(ap);
event_exit(eval);
}
@ -170,7 +168,7 @@ event_warnx(const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
warn_helper_(EVENT_LOG_WARN, NULL, fmt, ap);
event_logv_(EVENT_LOG_WARN, NULL, fmt, ap);
va_end(ap);
}
@ -180,7 +178,7 @@ event_msgx(const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
warn_helper_(EVENT_LOG_MSG, NULL, fmt, ap);
event_logv_(EVENT_LOG_MSG, NULL, fmt, ap);
va_end(ap);
}
@ -190,16 +188,19 @@ event_debugx_(const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
warn_helper_(EVENT_LOG_DEBUG, NULL, fmt, ap);
event_logv_(EVENT_LOG_DEBUG, NULL, fmt, ap);
va_end(ap);
}
static void
warn_helper_(int severity, const char *errstr, const char *fmt, va_list ap)
void
event_logv_(int severity, const char *errstr, const char *fmt, va_list ap)
{
char buf[1024];
size_t len;
if (severity == EVENT_LOG_DEBUG && !event_debug_get_logging_mask_())
return;
if (fmt != NULL)
evutil_vsnprintf(buf, sizeof(buf), fmt, ap);
else

View File

@ -1892,8 +1892,8 @@ struct testcase_t dns_testcases[] = {
{ "search", dns_search_test, TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
{ "search_cancel", dns_search_cancel_test,
TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
{ "retry", dns_retry_test, TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
{ "reissue", dns_reissue_test, TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
{ "retry", dns_retry_test, TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, NULL },
{ "reissue", dns_reissue_test, TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, NULL },
{ "inflight", dns_inflight_test, TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
{ "bufferevent_connect_hostname", test_bufferevent_connect_hostname,
TT_FORK|TT_NEED_BASE, &basic_setup, NULL },