[tor-commits] [stem/master] Showing shorter single-line controller messages
atagar at torproject.org
atagar at torproject.org
Wed Nov 23 18:06:36 UTC 2011
commit e3d4311962b7e95b882a9a50b2402b17f2f2d3d9
Author: Damian Johnson <atagar at torproject.org>
Date: Wed Nov 23 10:05:15 2011 -0800
Showing shorter single-line controller messages
When controller messages are on a single line logging them that way too, making
the output a little more readable. I should probably file send/recv at a trace
runlevel or with a separate logger...
---
stem/types.py | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/stem/types.py b/stem/types.py
index 66aa205..0bc3c45 100644
--- a/stem/types.py
+++ b/stem/types.py
@@ -95,7 +95,13 @@ def write_message(control_file, message, raw = False):
if not raw: message = format_write_message(message)
try:
- LOGGER.debug("Sending message:\n" + message.replace("\r\n", "\n").rstrip())
+ log_message = message.replace("\r\n", "\n").rstrip()
+
+ # starts with a newline if this is a multi-line message (more readable)
+ if "\n" in log_message: log_message = "\n" + log_message
+
+ LOGGER.debug("Sending: " + log_message)
+
control_file.write(message)
control_file.flush()
except socket.error, exc:
@@ -200,7 +206,12 @@ def read_message(control_file):
# replacing the \r\n newline endings and the ending newline since it
# leads to more readable log messages
- LOGGER.debug("Received message:\n" + raw_content.replace("\r\n", "\n").rstrip())
+ log_message = raw_content.replace("\r\n", "\n").rstrip()
+
+ # starts with a newline if this is a multi-line message (more readable)
+ if "\n" in log_message: log_message = "\n" + log_message
+
+ LOGGER.debug("Received: " + log_message)
return ControlMessage(parsed_content, raw_content)
elif divider == "+":
More information about the tor-commits
mailing list