diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2009-02-08 19:06:08 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2009-02-08 19:06:08 (GMT) |
commit | b20af944d27e6277a9afa9f01282673eb89f7cf6 (patch) | |
tree | f753b5744382b4126e2935663a9081f2754aea51 /Lib/logging | |
parent | 9e58a372524f86362921978f18b0aca07da57e20 (diff) | |
download | cpython-b20af944d27e6277a9afa9f01282673eb89f7cf6.zip cpython-b20af944d27e6277a9afa9f01282673eb89f7cf6.tar.gz cpython-b20af944d27e6277a9afa9f01282673eb89f7cf6.tar.bz2 |
Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index b265c21..8773225 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -758,17 +758,19 @@ class StreamHandler(Handler): """ try: msg = self.format(record) + stream = self.stream fs = "%s\n" if not hasattr(types, "UnicodeType"): #if no unicode support... - self.stream.write(fs % msg) + stream.write(fs % msg) else: try: - if getattr(self.stream, 'encoding', None) is not None: - self.stream.write(fs % msg.encode(self.stream.encoding)) + if (isinstance(msg, unicode) or + getattr(stream, 'encoding', None) is None): + stream.write(fs % msg) else: - self.stream.write(fs % msg) + stream.write(fs % msg.encode(stream.encoding)) except UnicodeError: - self.stream.write(fs % msg.encode("UTF-8")) + stream.write(fs % msg.encode("UTF-8")) self.flush() except (KeyboardInterrupt, SystemExit): raise |