]> granicus.if.org Git - python/commitdiff
logging: Made StreamHandler terminator configurable.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Wed, 20 Oct 2010 20:05:38 +0000 (20:05 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Wed, 20 Oct 2010 20:05:38 +0000 (20:05 +0000)
Lib/logging/__init__.py
Misc/NEWS

index 03ceb9c72b91c444523481a09d6f6e64e1f3903c..7f217d4c90fa6063aa5497be26613ddf83cc772a 100644 (file)
@@ -359,7 +359,7 @@ class Formatter(object):
     responsible for converting a LogRecord to (usually) a string which can
     be interpreted by either a human or an external system. The base Formatter
     allows a formatting string to be specified. If none is supplied, the
-    default value of "%s(message)\\n" is used.
+    default value of "%s(message)" is used.
 
     The Formatter can be initialized with a format string which makes use of
     knowledge of the LogRecord attributes - e.g. the default value mentioned
@@ -823,6 +823,8 @@ class StreamHandler(Handler):
     sys.stdout or sys.stderr may be used.
     """
 
+    terminator = '\n'
+
     def __init__(self, stream=None):
         """
         Initialize the handler.
@@ -855,8 +857,8 @@ class StreamHandler(Handler):
         try:
             msg = self.format(record)
             stream = self.stream
-            fs = "%s\n"
-            stream.write(fs % msg)
+            stream.write(msg)
+            stream.write(self.terminator)
             self.flush()
         except (KeyboardInterrupt, SystemExit):
             raise
index 16dad49f676042c4f5ba5ff42277d779e114cdb5..60d546f53681638331554b2ddc87047248f185e7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,8 @@ Core and Builtins
 Library
 -------
 
+- logging: Made StreamHandler terminator configurable.
+
 - logging: Allowed filters to be just callables.
 
 - logging: Added tests for _logRecordClass changes.