From 084818b3999c0d2656fd04dc0731b3f51f32152b Mon Sep 17 00:00:00 2001 From: Deniz Turgut Date: Sat, 4 May 2013 04:55:42 -0400 Subject: [PATCH] Handle critical exception logging correctly in localized systems Python generates certain exception messages (like IOError) in system language, if locale is set. This ensures that the message is properly converted to unicode in Python 2. --- pelican/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index 37f057f9..74499da4 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -378,7 +378,13 @@ def main(): pelican.run() except Exception as e: - logger.critical(e) + # localized systems have errors in native language if locale is set + # so convert the message to unicode with the correct encoding + msg = str(e) + if not six.PY3: + msg = msg.decode(locale.getpreferredencoding(False)) + + logger.critical(msg) if (args.verbosity == logging.DEBUG): raise