On redirecting standard output into a Python logger
TL;DR
We should document that Python bindings require the sys.stdout
object to provide an isatty()
method.
This need appears when we try to redirect sys.stdout
elsewhere, like for instance a Python logger.
Details
When using OTB applications through Python bindings, one may be tempted to redirect OTB logs into the Python logger currently configured for the application.
After a few minutes we find many solutions on stackoverflow or even directly available through pip. But, these solutions will induce a very cryptic error message (sorry I can't remember it, I fixed the issue a long time ago).
By injecting the solution proposed in https://github.com/swig/swig/issues/1117 we can find what goes wrong: the redirected output doesn't provide the isatty()
method.
I think this requirement should be documented in OTB cookbook in Python binding chapter.
For information a stdout 2 logger redirection compatible with OTB is provided in S1Tiling: https://gitlab.orfeo-toolbox.org/s1-tiling/s1tiling/-/blob/eodag/s1tiling/Utils.py#L256
Side notes
An open question is should we report this patch (for SWIG) (or a similar one, for licensing issues) into otbApplication.i
?