Peter Otten <[email protected]> added the comment:
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).
----------
nosy: +peter.otten
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36193>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com