.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_auto_examples/aequilibrae_project/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_aequilibrae_project_plot_logging_to_terminal.py: .. _logging_to_terminal: Logging to terminal =================== This example demonstrates how to configure and use the logging system in AequilibraE. For details of the logging setup used with AequilibraE see :ref:`logging_internals`. AequilibraE uses the standard Python `logging` module, but with specific configurations to ensure compatibility with: 1. Progress bars (tqdm), so logs do not break the visual bars in the terminal/notebook. 2. QGIS integration. 3. Multithreaded C++/Cython extensions. .. GENERATED FROM PYTHON SOURCE LINES 21-26 Basic Configuration ------------------- By default, AequilibraE does not configure the root logger to avoid interfering with other libraries or your own script's settings. To see AequilibraE logs in your terminal or notebook, you should use the provided helper. .. GENERATED FROM PYTHON SOURCE LINES 26-30 .. code-block:: Python import logging from aequilibrae.utils import basic_config .. GENERATED FROM PYTHON SOURCE LINES 31-33 This helper installs a custom StreamHandler that writes to ``stdout`` via ``tqdm.write``, ensuring that log messages print cleanly above active progress bars. .. GENERATED FROM PYTHON SOURCE LINES 33-41 .. code-block:: Python # Configure logging to INFO level handler = basic_config(level=logging.INFO) # Now we can log logger = logging.getLogger("aequilibrae") logger.info("This is a standard info message.") .. rst-class:: sphx-glr-script-out .. code-block:: none 2026-11-23 06:35:28,555;INFO ; This is a standard info message. .. GENERATED FROM PYTHON SOURCE LINES 42-54 How it works ------------ When :py:func:`aequilibrae.utils.logging_utils.basic_config` is called: 1. It sets the level for the ``"aequilibrae"`` logger. 2. It sets ``logger.propagate = False``. This prevents AequilibraE logs from bubbling up to the root logger. This is crucial because standard root handlers might print directly to streams that conflict with the terminal-based progress bars. 3. It attaches an ``aequilibrae.utils.logging_utils.AequilibraEStreamHandler`` which preserves the terminal-based progress bars. You can customise the format and stream: .. GENERATED FROM PYTHON SOURCE LINES 54-58 .. code-block:: Python logger.removeHandler(handler) basic_config(level=logging.DEBUG, format="%(levelname)s: %(message)s") logger.debug("This is a debug message with a custom format.") .. rst-class:: sphx-glr-script-out .. code-block:: none DEBUG: This is a debug message with a custom format. .. GENERATED FROM PYTHON SOURCE LINES 59-62 Note that we removed the first handler that ``basic_config`` added otherwise the message will appear twice. If the ``"aequilibrae"`` has any handlers writing to standard out or standard error then ``basic_config`` will do not do anything. .. GENERATED FROM PYTHON SOURCE LINES 64-68 Configuring Specific Modules ---------------------------- All AequilibraE logging happens under the ``"aequilibrae"`` namespace. You can fine-tune logging for specific modules if you want to debug only one part of the system. .. GENERATED FROM PYTHON SOURCE LINES 68-73 .. code-block:: Python # Example: Turn on DEBUG logging only for the paths module paths_logger = logging.getLogger("aequilibrae.routing") paths_logger.setLevel(logging.DEBUG) .. GENERATED FROM PYTHON SOURCE LINES 74-76 The parent ``"aequilibrae"`` logger might be set to WARNING, but this specific module will now output DEBUG messages. .. GENERATED FROM PYTHON SOURCE LINES 78-89 Scenario-Based Logging ---------------------- AequilibraE Projects handle logging automatically when switching scenarios. When you open a project athe Project attaches a specific `FileHandler` to the logger. * **One Log per Scenario:** If you run multiple scenarios, AequilibraE automatically switches the log file handler to a new file located in the scenario directory. * **Auto-Switching:** You do not need to manually close or remove handlers; the logging system handles the rotation to ensure logs from scenario A don't end up in scenario B's file. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.887 seconds) .. _sphx_glr_download__auto_examples_aequilibrae_project_plot_logging_to_terminal.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_logging_to_terminal.ipynb ` .. 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-zip :download:`Download zipped: plot_logging_to_terminal.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_