Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a20dfc

Browse files
committed
logging: Made StreamHandler terminator configurable.
1 parent f3500e1 commit 2a20dfc

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/logging/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ class Formatter(object):
359359
responsible for converting a LogRecord to (usually) a string which can
360360
be interpreted by either a human or an external system. The base Formatter
361361
allows a formatting string to be specified. If none is supplied, the
362-
default value of "%s(message)\\n" is used.
362+
default value of "%s(message)" is used.
363363
364364
The Formatter can be initialized with a format string which makes use of
365365
knowledge of the LogRecord attributes - e.g. the default value mentioned
@@ -823,6 +823,8 @@ class StreamHandler(Handler):
823823
sys.stdout or sys.stderr may be used.
824824
"""
825825

826+
terminator = '\n'
827+
826828
def __init__(self, stream=None):
827829
"""
828830
Initialize the handler.
@@ -855,8 +857,8 @@ def emit(self, record):
855857
try:
856858
msg = self.format(record)
857859
stream = self.stream
858-
fs = "%s\n"
859-
stream.write(fs % msg)
860+
stream.write(msg)
861+
stream.write(self.terminator)
860862
self.flush()
861863
except (KeyboardInterrupt, SystemExit):
862864
raise

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Core and Builtins
3434
Library
3535
-------
3636

37+
- logging: Made StreamHandler terminator configurable.
38+
3739
- logging: Allowed filters to be just callables.
3840

3941
- logging: Added tests for _logRecordClass changes.

0 commit comments

Comments
 (0)