[tor-commits] [stem/master] Truncate trace level logging
atagar at torproject.org
atagar at torproject.org
Mon Feb 1 04:21:04 UTC 2016
commit 82a7ae8a2dd170bbf4ec3183ce170a107d73d116
Author: Damian Johnson <atagar at torproject.org>
Date: Sun Jan 31 13:57:16 2016 -0800
Truncate trace level logging
At the trace level we have request/reply logging. Very useful, but some tor
requests like 'GETINFO ns/all' are huge. Truncating responses to ten lines by
default. This can be customized via a constant.
This reduces the debug log when nyx is run for a few seconds from 1.6M to 80K,
mostly because it no longer causes us to dump the full consensus into it.
---
stem/socket.py | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/stem/socket.py b/stem/socket.py
index 473debe..de57c7d 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -80,6 +80,10 @@ import stem.util.str_tools
from stem.util import log
+# lines to limit our trace logging to, you can disable this by setting it to None
+
+TRUNCATE_LOGS = 10
+
class ControlSocket(object):
"""
@@ -589,6 +593,13 @@ def recv_message(control_file):
raw_content_str = b''.join(raw_content)
log_message = raw_content_str.replace(b'\r\n', b'\n').rstrip()
+
+ if TRUNCATE_LOGS:
+ log_message_lines = log_message.split(b'\n')
+
+ if len(log_message_lines) > TRUNCATE_LOGS:
+ log_message = b'\n'.join(log_message_lines[:TRUNCATE_LOGS] + [b'... %i more lines...' % (len(log_message_lines) - TRUNCATE_LOGS)])
+
log.trace('Received from tor:\n' + stem.util.str_tools._to_unicode(log_message))
return stem.response.ControlMessage(parsed_content, raw_content_str)
More information about the tor-commits
mailing list