Commit 802c1e85 authored by Jason Madden's avatar Jason Madden

Fix #756. Don't throw extra newlines on log messages sent to a Logger.

parent 987d621e
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
waiting greenlets in the same (unspecified) order. Previously, waiting greenlets in the same (unspecified) order. Previously,
``AsyncResult`` tended to use a FIFO order, but this was never ``AsyncResult`` tended to use a FIFO order, but this was never
guaranteed. Both classes also use less per-instance memory. guaranteed. Both classes also use less per-instance memory.
- Using a :class:`~logging.Logger` as a :mod:`pywsgi` error or request
log stream no longer produces extra newlines. Reported in
:issue:`756` by ael-code.
.. _bug 13502: http://bugs.python.org/issue13502 .. _bug 13502: http://bugs.python.org/issue13502
......
...@@ -1059,6 +1059,10 @@ class LoggingLogAdapter(object): ...@@ -1059,6 +1059,10 @@ class LoggingLogAdapter(object):
Attributes not present on this object are proxied to the underlying Attributes not present on this object are proxied to the underlying
logger instance. This permits using custom :class:`~logging.Logger` logger instance. This permits using custom :class:`~logging.Logger`
subclasses (or indeed, even duck-typed objects). subclasses (or indeed, even duck-typed objects).
.. versionchanged:: 1.1
Strip trailing newline characters on the message passed to :meth:`write`
because log handlers will usually add one themselves.
""" """
# gevent avoids importing and using logging because importing it and # gevent avoids importing and using logging because importing it and
...@@ -1074,6 +1078,8 @@ class LoggingLogAdapter(object): ...@@ -1074,6 +1078,8 @@ class LoggingLogAdapter(object):
self._level = level self._level = level
def write(self, msg): def write(self, msg):
if msg and msg.endswith('\n'):
msg = msg[:-1]
self._logger.log(self._level, msg) self._logger.log(self._level, msg)
def flush(self): def flush(self):
......
...@@ -1528,8 +1528,11 @@ class TestLogging(TestCase): ...@@ -1528,8 +1528,11 @@ class TestLogging(TestCase):
def test_status_log(self): def test_status_log(self):
# Issue 664: Make sure we format the status line as a string # Issue 664: Make sure we format the status line as a string
self.urlopen() self.urlopen()
self.assertTrue('"GET / HTTP/1.1" 200 ' in self.server.log.logged[1], msg = self.server.log.logged[1]
self.server.log.logged[1]) self.assertTrue('"GET / HTTP/1.1" 200 ' in msg, msg)
# Issue 756: Make sure we don't throw a newline on the end
self.assertTrue('\n' not in msg, msg)
del CommonTests del CommonTests
......
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