Fix non-unicode error messages

Ref #645
This commit is contained in:
ZyX 2014-08-29 21:05:54 +04:00
parent d455cec319
commit d138c94704
1 changed files with 7 additions and 1 deletions

View File

@ -67,9 +67,15 @@ class PowerlineLogger(object):
def _log(self, attr, msg, *args, **kwargs):
prefix = kwargs.get('prefix') or self.prefix
prefix = self.ext + ((':' + prefix) if prefix else '')
msg = safe_unicode(msg)
if args or kwargs:
args = [safe_unicode(s) if isinstance(s, bytes) else s for s in args]
kwargs = dict((
(k, safe_unicode(v) if isinstance(v, bytes) else v)
for k, v in kwargs.items()
))
msg = msg.format(*args, **kwargs)
msg = prefix + ':' + safe_unicode(msg)
msg = prefix + ':' + msg
key = attr + ':' + prefix
if msg != self.last_msgs.get(key):
getattr(self.logger, attr)(msg)