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.

Author peter.otten
Recipients andriusl, peter.otten, vinay.sajip, xtreak
Date 2019-03-05.14:37:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1551796678.83.0.224252752433.issue36193@roundup.psfhosted.org>
In-reply-to
Content
I see various options to address this.

(1) Change basicConfig() to use __stderr__ instead of stderr to avoid redirections from within the script.

(2) Change your script to call basicConfig() explicitly, before the temporary redirection takes place. 

In both cases logging output will always go to the "real" stderr.

(3) Write a special handler that fetches sys.stderr lazily. Here's a sketch:

class StderrHandler(logging.StreamHandler):
    def __init__(self):
        super().__init__()

    def get_stream(self):
        return sys.stderr

    def set_stream(self, _value):
        pass

    stream = property(get_stream, set_stream)

logging.basicConfig(handlers=[StderrHandler()])

As written this is likely to fail with multiple threads...

My personal favourite is option (2).
History
Date User Action Args
2019-03-05 14:37:58peter.ottensetrecipients: + peter.otten, vinay.sajip, xtreak, andriusl
2019-03-05 14:37:58peter.ottensetmessageid: <1551796678.83.0.224252752433.issue36193@roundup.psfhosted.org>
2019-03-05 14:37:58peter.ottenlinkissue36193 messages
2019-03-05 14:37:58peter.ottencreate