From 946386a8e7813355b51967c13fa714e576ef2655 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 6 Jan 2012 23:40:31 +0100 Subject: [PATCH] Restore previous MachineUI output a bit more The logging rework led to multipline output as we stopped urlencoding the output lines. Urrg. Fixed this, so output is urlencoded again. Signed-off-by: Sebastian Spaeth --- offlineimap/ui/Machine.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/offlineimap/ui/Machine.py b/offlineimap/ui/Machine.py index e6d1877..ab57ea2 100644 --- a/offlineimap/ui/Machine.py +++ b/offlineimap/ui/Machine.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - +from urllib import urlencode import sys import time import logging @@ -23,15 +23,24 @@ import offlineimap protocol = '7.0.0' +class MachineLogFormatter(logging.Formatter): + """urlencodes any outputted line, to avoid multi-line output""" + def format(self, record): + # urlencode the "mesg" attribute and append to regular line... + line = super(MachineLogFormatter, self).format(record) + return line + urlencode([('', record.mesg)])[1:] + class MachineUI(UIBase): def __init__(self, config, loglevel = logging.INFO): super(MachineUI, self).__init__(config, loglevel) self._log_con_handler.createLock() """lock needed to block on password input""" + # Set up the formatter that urlencodes the strings... + self._log_con_handler.setFormatter(MachineLogFormatter()) def _printData(self, command, msg): - self.logger.info("%s:%s:%s:%s" % ( - 'msg', command, currentThread().getName(), msg)) + self.logger.info("%s:%s:%s" % ( + 'msg', command, currentThread().getName()), extra={'mesg': msg}) def _msg(s, msg): s._printData('_display', msg)