.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/programmers/plot_biogeme_logging.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_programmers_plot_biogeme_logging.py: biogeme.biogeme_logging ======================= Examples of use of several functions. This is designed for programmers who need examples of use of the functions of the module. The examples are designed to illustrate the syntax. They do not correspond to any meaningful model. Michel Bierlaire Sun Jun 29 2025, 02:24:09 .. GENERATED FROM PYTHON SOURCE LINES 17-22 .. code-block:: Python import os import biogeme.biogeme_logging as blog from biogeme.version import get_text .. GENERATED FROM PYTHON SOURCE LINES 23-24 Version of Biogeme. .. GENERATED FROM PYTHON SOURCE LINES 24-26 .. code-block:: Python print(get_text()) .. rst-class:: sphx-glr-script-out .. code-block:: none biogeme 3.3.1 [2025-09-03] Home page: http://biogeme.epfl.ch Submit questions to https://groups.google.com/d/forum/biogeme Michel Bierlaire, Transport and Mobility Laboratory, Ecole Polytechnique Fédérale de Lausanne (EPFL) .. GENERATED FROM PYTHON SOURCE LINES 27-36 In Python, the levels of reporting are: - DEBUG - INFO - WARNING - ERROR - CRITICAL In Biogeme, we basically use the first three. .. GENERATED FROM PYTHON SOURCE LINES 38-41 If we request a specific level, all messages from this level and all levels above are displayed. For example, if INFO is requested, everything except DEBUG will be displayed. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: Python logger = blog.get_screen_logger(level=blog.INFO) .. GENERATED FROM PYTHON SOURCE LINES 45-47 .. code-block:: Python logger.info('A test') .. rst-class:: sphx-glr-script-out .. code-block:: none A test .. GENERATED FROM PYTHON SOURCE LINES 48-50 If a debug message is generated, it is not displayed, as the INFO level has been requested above. .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: Python logger.debug('A debug message') .. GENERATED FROM PYTHON SOURCE LINES 55-56 But a warning message is displayed, as it comes higher in the hierarchy. .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. code-block:: Python logger.warning('A warning message') .. rst-class:: sphx-glr-script-out .. code-block:: none A warning message .. GENERATED FROM PYTHON SOURCE LINES 61-62 It is also possible to log the messages on file. .. GENERATED FROM PYTHON SOURCE LINES 64-66 .. code-block:: Python THE_FILE = '_test.log' .. GENERATED FROM PYTHON SOURCE LINES 67-68 Let's first erase the file if it happens to exist. .. GENERATED FROM PYTHON SOURCE LINES 68-74 .. code-block:: Python try: os.remove(THE_FILE) print(f'File {THE_FILE} has been erased.') except FileNotFoundError: print('File {THE_FILE} does not exist.') .. rst-class:: sphx-glr-script-out .. code-block:: none File _test.log has been erased. .. GENERATED FROM PYTHON SOURCE LINES 75-77 .. code-block:: Python file_logger = blog.get_file_logger(filename=THE_FILE, level=blog.DEBUG) .. GENERATED FROM PYTHON SOURCE LINES 78-82 .. code-block:: Python file_logger.debug('A debug message') file_logger.warning('A warning message') file_logger.info('A info message') .. rst-class:: sphx-glr-script-out .. code-block:: none A warning message A info message .. GENERATED FROM PYTHON SOURCE LINES 83-86 Here is the content of the log file. Note that the message includes the filename, which is not informative in the context of this Notebook. .. GENERATED FROM PYTHON SOURCE LINES 88-90 .. code-block:: Python with open(THE_FILE, encoding='utf-8') as f: print(f.read()) .. rst-class:: sphx-glr-script-out .. code-block:: none [DEBUG] 2025-09-03 01:58:55,791 A debug message [WARNING] 2025-09-03 01:58:55,792 A warning message [INFO] 2025-09-03 01:58:55,792 A info message .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.006 seconds) .. _sphx_glr_download_auto_examples_programmers_plot_biogeme_logging.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_biogeme_logging.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_biogeme_logging.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_biogeme_logging.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_