-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-30522: Implemented a method to allow setting a logging.StreamHand… #2921
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -997,6 +997,26 @@ def emit(self, record): | |
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the flush need here? The only place to write steam is emit(),that already has a flush. If the flush is not needed, the lock is also not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may seem a bit defensive but is unlikely to be in performance-critical code, I would have thought. |
||
self.stream = stream | ||
finally: | ||
self.release() | ||
return result | ||
|
||
def __repr__(self): | ||
level = getLevelName(self.level) | ||
name = getattr(self.stream, 'name', '') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Added a ``setStream`` method to ``logging.StreamHandler`` to allow the | ||
stream to be set after creation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method needs a
versionadded
marker.