Skip to content

Commit

Permalink
logging: Made StreamHandler terminator configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
vsajip committed Oct 20, 2010
1 parent f3500e1 commit 2a20dfc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -855,8 +857,8 @@ def emit(self, record):
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
Expand Down
2 changes: 2 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2a20dfc

Please sign in to comment.