From eb12afe6999149320035be435fb2cc101250c710 Mon Sep 17 00:00:00 2001 From: y12studio Date: Mon, 8 Sep 2014 18:19:17 +0800 Subject: [PATCH] utf-8 and json dump log --- node/tornadoloop.py | 7 +++---- node/transport.py | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/node/tornadoloop.py b/node/tornadoloop.py index 09132dc20..765709752 100755 --- a/node/tornadoloop.py +++ b/node/tornadoloop.py @@ -146,13 +146,12 @@ def start_node(my_market_ip, disable_open_browser=False): logging.basicConfig(level=int(log_level), - format='%(asctime)s - %(name)s - \ - %(levelname)s - %(message)s', + format=u'%(asctime)s - %(name)s - %(levelname)s - %(message)s', filename=log_file) - + logging._defaultFormatter = logging.Formatter(u'%(message)s') locallogger = logging.getLogger('[%s] %s' % (market_id, 'root')) - handler = logging.handlers.RotatingFileHandler(log_file, + handler = logging.handlers.RotatingFileHandler(log_file, encoding='utf-8', maxBytes=50, backupCount=0) locallogger.addHandler(handler) diff --git a/node/transport.py b/node/transport.py index fe42ecf38..37166591e 100644 --- a/node/transport.py +++ b/node/transport.py @@ -405,7 +405,7 @@ def get_market_id(self): def _ping(self, msg): - self.log.info('Pinged %s ' % pformat(msg)) + self.log.info('Pinged %s ' % json.dumps(msg, ensure_ascii=False)) # # pinger = CryptoPeerConnection(self, msg['uri'], msg['pubkey'], msg['senderGUID']) # pinger.send_raw(json.dumps( @@ -789,7 +789,7 @@ def _on_message(self, msg): nickname = msg.get('senderNick')[:120] self.dht.add_known_node((ip, port, guid, nickname)) - self.log.info('ON MESSAGE %s' % msg) + self.log.info('ON MESSAGE %s' % json.dumps(msg, ensure_ascii=False)) self.dht.add_peer(self, uri, pubkey, guid, nickname)