summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2017-07-30 09:41:45 (GMT)
committerGitHub <noreply@github.com>2017-07-30 09:41:45 (GMT)
commit2543f50033208c1a8df04999082b11aa09e82a04 (patch)
treeb74c99e4821404d6dfdc4d0076e0810690bcff73 /Lib/logging
parent78c18a9b9a1445f7c755929917a790ba02b4a5e0 (diff)
downloadcpython-2543f50033208c1a8df04999082b11aa09e82a04.zip
cpython-2543f50033208c1a8df04999082b11aa09e82a04.tar.gz
cpython-2543f50033208c1a8df04999082b11aa09e82a04.tar.bz2
bpo-30522: Implemented a method to allow setting a logging.StreamHander's stream. (GH-2921)
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index f9bfb79..54d4e88 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -997,6 +997,26 @@ class StreamHandler(Handler):
except Exception:
self.handleError(record)
+ def setStream(self, stream):
+ """
+ Sets the StreamHandler's stream to the specified value,
+ if it is different.
+
+ Returns the old stream, if the stream was changed, or None
+ if it wasn't.
+ """
+ if stream is self.stream:
+ result = None
+ else:
+ result = self.stream
+ self.acquire()
+ try:
+ self.flush()
+ self.stream = stream
+ finally:
+ self.release()
+ return result
+
def __repr__(self):
level = getLevelName(self.level)
name = getattr(self.stream, 'name', '')