aboutsummaryrefslogtreecommitdiff
path: root/src/test/log_test_helpers.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-08-31 12:51:22 -0400
committerNick Mathewson <nickm@torproject.org>2016-08-31 12:51:22 -0400
commitf74916a98f97c7e80e46400e921d54466285d1fb (patch)
treedc1859cd46e31bdc36289f6b7a0f2207e90d6d2e /src/test/log_test_helpers.c
parent1f7dc823c5077101e4b0760ded1d7259d57d7506 (diff)
downloadtor-f74916a98f97c7e80e46400e921d54466285d1fb.tar.gz
tor-f74916a98f97c7e80e46400e921d54466285d1fb.zip
setup_capture_of_logs: no longer suppress log messages
Previously setup_capture_of_logs would prevent log messages from going to the console entirely. That's a problem, since sometimes log messages are bugs! Now setup_capture_of_logs() acts sensibly. If you really do need to keep a message from going to the console entirely, there is setup_full_capture_of_logs(). But only use that if you're prepared to make sure that there are no extraneous messages generated at all.
Diffstat (limited to 'src/test/log_test_helpers.c')
-rw-r--r--src/test/log_test_helpers.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/test/log_test_helpers.c b/src/test/log_test_helpers.c
index 1828689d1d..8b67c39bca 100644
--- a/src/test/log_test_helpers.c
+++ b/src/test/log_test_helpers.c
@@ -6,6 +6,16 @@
static smartlist_t *saved_logs = NULL;
+static int echo_to_real_logs = 1;
+
+int
+setup_full_capture_of_logs(int new_level)
+{
+ int result = setup_capture_of_logs(new_level);
+ echo_to_real_logs = 0;
+ return result;
+}
+
int
setup_capture_of_logs(int new_level)
{
@@ -14,6 +24,7 @@ setup_capture_of_logs(int new_level)
mock_clean_saved_logs();
saved_logs = smartlist_new();
MOCK(logv, mock_saving_logv);
+ echo_to_real_logs = 1;
return previous_log;
}
@@ -108,7 +119,6 @@ mock_saving_logv(int severity, log_domain_mask_t domain,
const char *funcname, const char *suffix,
const char *format, va_list ap)
{
- (void)domain;
char *buf = tor_malloc_zero(10240);
int n;
n = tor_vsnprintf(buf,10240,format,ap);
@@ -127,5 +137,9 @@ mock_saving_logv(int severity, log_domain_mask_t domain,
if (!saved_logs)
saved_logs = smartlist_new();
smartlist_add(saved_logs, e);
+
+ if (echo_to_real_logs) {
+ tor_log(severity, domain|LD_NO_MOCK, "%s", e->generated_msg);
+ }
}