Kaydet (Commit) 72ed0784 authored tarafından Vinay Sajip's avatar Vinay Sajip

logging: fixed lack of use of encoding attribute specified on a stream.

üst f7dd75f4
...@@ -719,6 +719,7 @@ class StreamHandler(Handler): ...@@ -719,6 +719,7 @@ class StreamHandler(Handler):
to a stream. Note that this class does not close the stream, as to a stream. Note that this class does not close the stream, as
sys.stdout or sys.stderr may be used. sys.stdout or sys.stderr may be used.
""" """
def __init__(self, strm=None): def __init__(self, strm=None):
""" """
Initialize the handler. Initialize the handler.
...@@ -743,10 +744,11 @@ class StreamHandler(Handler): ...@@ -743,10 +744,11 @@ class StreamHandler(Handler):
Emit a record. Emit a record.
If a formatter is specified, it is used to format the 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 The record is then written to the stream with a trailing newline. If
[N.B. this may be removed depending on feedback]. If exception exception information is present, it is formatted using
information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream
traceback.print_exception and appended to the stream. has an 'encoding' attribute, it is used to encode the message before
output to the stream.
""" """
try: try:
msg = self.format(record) msg = self.format(record)
...@@ -755,6 +757,9 @@ class StreamHandler(Handler): ...@@ -755,6 +757,9 @@ class StreamHandler(Handler):
self.stream.write(fs % msg) self.stream.write(fs % msg)
else: else:
try: try:
if hasattr(self.stream, 'encoding'):
self.stream.write(fs % msg.encode(self.stream.encoding))
else:
self.stream.write(fs % msg) self.stream.write(fs % msg)
except UnicodeError: except UnicodeError:
self.stream.write(fs % msg.encode("UTF-8")) self.stream.write(fs % msg.encode("UTF-8"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment