I am using python
3.7.6
. and abseil module for logging messages with absl-py
0.9.0
. I am using this piece of code for my tests.
from absl import logging
from absl import app
def main(argv):
#logging.set_stderrthreshold(logging.ERROR)
#logging._warn_preinit_stderr = False
logging.set_verbosity(logging.DEBUG)
print(' 0 -----')
logging.debug(' 1 logging-debug-test')
logging.info(' 2 logging-info-test')
logging.warning(' 3 logging-warning-test')
logging.error('4 logging-error-test')
print(' 5 -----')
if __name__ == '__main__':
app.run(main)
When testing it in a Jupyter notebook
, it is clear from the color code of the background that abseil messages are in the stderr stream.
Same things when executing the python code in a shell:
I tried few things with different values like:
logging.set_stderrthreshold(logging.DEBUG)
logging._warn_preinit_stderr = True
but I still see 100% the same output.
- How can I redirect output abseil logging messages to stdout instead of stderr ?
- Is it expected to have the logging output messages redirect to stderr and not stdout? I am probably missing something with the logging logic and I want to better understand it.
I was told that this is the standard behavior and what Python's standard logging module does. In my case adding the following line redirect the logging messages to stdout:
Now in my Jupyter notebook it looks like that: