This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Allow replacing a logging.StreamHandler's stream
Type: enhancement Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pitrou, vinay.sajip, vstinner
Priority: normal Keywords:

Created on 2017-05-31 08:09 by pitrou, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2921 closed vinay.sajip, 2017-07-27 18:52
Messages (6)
msg294820 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-05-31 08:09
Right now it is probably possible using something like:

    handler.acquire()
    try:
        handler.flush()
        handler.stream = new_stream
    finally:
        handler.release()

but it would be nice to have an officially-supported method to do that.

Context: if I reconfigure sys.stderr, I'd like to update all handlers that have a reference to the old sys.stderr.
msg294821 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-05-31 08:10
Which StreamHandler class? Is this issue related to logging? If yes, please mention it in the title ;-)
msg294822 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-05-31 08:10
Oh, yes, sorry.  This is about logging.
msg297957 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2017-07-08 14:45
How about this as an API?

    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.
        """
msg297958 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-07-08 15:20
Vinay, yes, that sounds fine to me.
msg299495 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2017-07-30 09:41
New changeset 2543f50033208c1a8df04999082b11aa09e82a04 by Vinay Sajip in branch 'master':
bpo-30522: Implemented a method to allow setting a logging.StreamHander's stream. (GH-2921)
https://github.com/python/cpython/commit/2543f50033208c1a8df04999082b11aa09e82a04
History
Date User Action Args
2022-04-11 14:58:47adminsetgithub: 74707
2017-07-30 09:44:33vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: resolved
2017-07-30 09:41:48vinay.sajipsetmessages: + msg299495
2017-07-27 18:52:48vinay.sajipsetpull_requests: + pull_request2975
2017-07-08 15:20:50pitrousetmessages: + msg297958
2017-07-08 14:45:12vinay.sajipsetmessages: + msg297957
2017-05-31 08:10:30pitrousetmessages: + msg294822
title: Allow replacing a StreamHandler's stream -> Allow replacing a logging.StreamHandler's stream
2017-05-31 08:10:05vstinnersetnosy: + vstinner
messages: + msg294821
2017-05-31 08:09:10pitroucreate