[Python-checkins] r66103 - python/trunk/Lib/logging/__init__.py
vinay.sajip
python-checkins at python.org
Mon Sep 1 16:30:10 CEST 2008
Author: vinay.sajip
Date: Mon Sep 1 16:30:10 2008
New Revision: 66103
Log:
logging: fixed lack of use of encoding attribute specified on a stream.
Modified:
python/trunk/Lib/logging/__init__.py
Modified: python/trunk/Lib/logging/__init__.py
==============================================================================
--- python/trunk/Lib/logging/__init__.py (original)
+++ python/trunk/Lib/logging/__init__.py Mon Sep 1 16:30:10 2008
@@ -719,6 +719,7 @@
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 @@
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 @@
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()
More information about the Python-checkins
mailing list