logging output is out of order in Jupyter Notebook, here is an example.
Plain ipython session:
In [1]: import logging
In [2]: for i in range(5):
...: print(i)
...: if i == 3:
...: logging.critical("critical")
...:
0
1
2
3
CRITICAL:root:critical
4
In [3]:
but in a Jupyter Notebook the output is out of order:

The logging output is printed before everything else. This makes debugging impossible as one loses any indication where the logging statement occured.
This happens with any logging level.
How can I get output in the correct order, as opposed to logging output getting its own special place?
You can fix this by setting the stream to sys.stdout. This will remove any special treatment for logging messages in Jupyter Notebook I guess.
import logging
import sys
logging.basicConfig(stream=sys.stdout)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With