summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2008-09-01 14:30:10 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2008-09-01 14:30:10 (GMT)
commit72ed07843a35be60e2c5e1d9675b9c97c5cb402d (patch)
tree371f656d006fe0854476356b6e558f8955231c10 /Lib/logging
parentf7dd75f48465012a2847f698f36dba59b5955689 (diff)
downloadcpython-72ed07843a35be60e2c5e1d9675b9c97c5cb402d.zip
cpython-72ed07843a35be60e2c5e1d9675b9c97c5cb402d.tar.gz
cpython-72ed07843a35be60e2c5e1d9675b9c97c5cb402d.tar.bz2
logging: fixed lack of use of encoding attribute specified on a stream.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index ae001db..9026ef3 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -719,6 +719,7 @@ class StreamHandler(Handler):
to a stream. Note that this class does not close the stream, as
sys.stdout or sys.stderr may be used.
"""
+
def __init__(self, strm=None):
"""
Initialize the handler.
@@ -743,10 +744,11 @@ class StreamHandler(Handler):
Emit a record.
If a formatter is specified, it is used to format the record.
- The record is then written to the stream with a trailing newline
- [N.B. this may be removed depending on feedback]. If exception
- information is present, it is formatted using
- traceback.print_exception and appended to the stream.
+ The record is then written to the stream with a trailing newline. If
+ exception information is present, it is formatted using
+ traceback.print_exception and appended to the stream. If the stream
+ has an 'encoding' attribute, it is used to encode the message before
+ output to the stream.
"""
try:
msg = self.format(record)
@@ -755,7 +757,10 @@ class StreamHandler(Handler):
self.stream.write(fs % msg)
else:
try:
- self.stream.write(fs % msg)
+ if hasattr(self.stream, 'encoding'):
+ self.stream.write(fs % msg.encode(self.stream.encoding))
+ else:
+ self.stream.write(fs % msg)
except UnicodeError:
self.stream.write(fs % msg.encode("UTF-8"))
self.flush()