fix logging raw_data and decodec_data
@@ -18,6 +18,7 @@ __email__ = 'grzegorz.latuszek@nokia.com'
import logging
import platform
import weakref
+from quopri import decodestring
from threading import Lock
import six
@@ -189,9 +190,16 @@ class ObservableConnection(Connection):
Incoming-IO API:
external-IO should call this method when data is received
"""
- self._log(msg=data, level=RAW_DATA, extra={'transfer_direction': '<'})
+ # log input as ascii printable (for non-ascii dump as \0x prefixed bytes)
+ printable_data = decodestring(data)
+ self._log(msg=printable_data, level=RAW_DATA, extra={'transfer_direction': '<'})
+
decoded_data = self.decode(data)
- self._log(msg=decoded_data, level=logging.INFO, extra={'transfer_direction': '<'})
+ # decoded data is in general unicode string, logger accepts only ascii.
+ # We create ascii logs interpretable as utf-8 bytes.
+ # Editor with utf-8 support can correctly display such logs.
+ self._log(msg=decoded_data.encode('utf-8'), level=logging.INFO, extra={'transfer_direction': '<'})
+
self.notify_observers(decoded_data)
def subscribe(self, observer):
