.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_auto_examples/plot_logging_to_terminal.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__auto_examples_plot_logging_to_terminal.py: Logging to terminal =================== On this example we show how to make all log messages show in the terminal. .. GENERATED FROM PYTHON SOURCE LINES 9-10 # Imports .. GENERATED FROM PYTHON SOURCE LINES 10-17 .. code-block:: python from uuid import uuid4 from tempfile import gettempdir from os.path import join from aequilibrae.utils.create_example import create_example import logging import sys .. GENERATED FROM PYTHON SOURCE LINES 18-19 We create the example project inside our temp folder .. GENERATED FROM PYTHON SOURCE LINES 19-23 .. code-block:: python fldr = join(gettempdir(), uuid4().hex) project = create_example(fldr) logger = project.logger .. GENERATED FROM PYTHON SOURCE LINES 24-25 With the project open, we can tell the logger to direct all messages to the terminal as well .. GENERATED FROM PYTHON SOURCE LINES 25-30 .. code-block:: python stdout_handler = logging.StreamHandler(sys.stdout) formatter = logging.Formatter("%(asctime)s;%(levelname)s ; %(message)s") stdout_handler.setFormatter(formatter) logger.addHandler(stdout_handler) .. GENERATED FROM PYTHON SOURCE LINES 31-33 .. code-block:: python project.close() .. GENERATED FROM PYTHON SOURCE LINES 34-35 **Want to see what you will get?** .. GENERATED FROM PYTHON SOURCE LINES 37-42 .. code-block:: python from PIL import Image import matplotlib.pyplot as plt img = Image.open("plot_logging_to_terminal_image.png") plt.imshow(img) .. image-sg:: /_auto_examples/images/sphx_glr_plot_logging_to_terminal_001.png :alt: plot logging to terminal :srcset: /_auto_examples/images/sphx_glr_plot_logging_to_terminal_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.239 seconds) .. _sphx_glr_download__auto_examples_plot_logging_to_terminal.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_logging_to_terminal.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_logging_to_terminal.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_