
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "basic_examples/plot_logging_configuration.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_basic_examples_plot_logging_configuration.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_basic_examples_plot_logging_configuration.py:


Configuring verbosity level
===========================

This example demonstrates how to configure verbosity level, or logging, using a coregistration method.
Logging can be customized to various severity levels, from ``DEBUG`` for detailed diagnostic output, to ``INFO`` for
general updates, ``WARNING`` for potential issues, and ``ERROR`` or ``CRITICAL`` for serious problems.

Setting the verbosity to a certain severity level prints all outputs from that level and those above. For instance,
level ``INFO`` also prints warnings, error and critical messages.

See also :ref:`config`.

.. important:: The verbosity level defaults to ``WARNING``, so no ``INFO`` or ``DEBUG`` is printed.

.. GENERATED FROM PYTHON SOURCE LINES 16-21

.. code-block:: Python


    import logging

    import xdem








.. GENERATED FROM PYTHON SOURCE LINES 22-23

We start by configuring the logging level, which can be as simple as specifying we want to print information.

.. GENERATED FROM PYTHON SOURCE LINES 23-25

.. code-block:: Python

    logging.basicConfig(level=logging.INFO)








.. GENERATED FROM PYTHON SOURCE LINES 26-27

We can change the configuration even more by specifying the format, date, and multiple destinations for the output.

.. GENERATED FROM PYTHON SOURCE LINES 27-38

.. code-block:: Python

    logging.basicConfig(
        level=logging.INFO,  # Change this level to DEBUG or WARNING to see different outputs.
        format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S",
        handlers=[
            logging.FileHandler("../xdem_example.log"),  # Save logs to a file
            logging.StreamHandler(),  # Also print logs to the console
        ],
        force=True,  # To re-set from previous logging
    )








.. GENERATED FROM PYTHON SOURCE LINES 39-40

We can now load example files and demonstrate the logging through a functionality, such as coregistration.

.. GENERATED FROM PYTHON SOURCE LINES 40-44

.. code-block:: Python

    reference_dem = xdem.DEM(xdem.examples.get_path("longyearbyen_ref_dem"))
    dem_to_be_aligned = xdem.DEM(xdem.examples.get_path("longyearbyen_tba_dem"))
    coreg = xdem.coreg.NuthKaab()








.. GENERATED FROM PYTHON SOURCE LINES 45-46

With the ``INFO`` verbosity level defined above, we can follow the iteration with a detailed format, saved to file.

.. GENERATED FROM PYTHON SOURCE LINES 46-48

.. code-block:: Python

    aligned_dem = coreg.fit_and_apply(reference_dem, dem_to_be_aligned)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    2026-04-30 08:22:40 - root - INFO - Running Nuth and Kääb (2011) coregistration
       Progress:   0%|          | 0/10 [00:00<?, ?it/s]                                                             Iteration #1 - Offset: (np.float64(-8.309815337601904), np.float64(-1.125693938821563), -2.7552547454833984); Magnitude: 0.4192857551507786
       Progress:   0%|          | 0/10 [00:00<?, ?it/s]       Progress:  10%|█         | 1/10 [00:00<00:02,  3.67it/s]                                                                     Iteration #2 - Offset: (np.float64(-8.588458139140956), np.float64(-1.255261994098664), -2.4402336216360823); Magnitude: 0.01536470727005738
       Progress:  10%|█         | 1/10 [00:00<00:02,  3.67it/s]       Progress:  20%|██        | 2/10 [00:00<00:02,  3.71it/s]                                                                     Iteration #3 - Offset: (np.float64(-8.588457830044044), np.float64(-1.267515250117788), -2.426217934828969); Magnitude: 0.0006126628011511315
       Progress:  20%|██        | 2/10 [00:00<00:02,  3.71it/s]                                                                  Last offset was below the residual offset threshold of 0.001 -> stopping
       Progress:  20%|██        | 2/10 [00:00<00:02,  3.71it/s]       Progress:  20%|██        | 2/10 [00:00<00:03,  2.46it/s]




.. GENERATED FROM PYTHON SOURCE LINES 49-50

With a more severe verbosity level, there is no output.

.. GENERATED FROM PYTHON SOURCE LINES 50-52

.. code-block:: Python

    logging.basicConfig(level=logging.ERROR, force=True)
    aligned_dem = coreg.fit_and_apply(reference_dem, dem_to_be_aligned)








.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.993 seconds)


.. _sphx_glr_download_basic_examples_plot_logging_configuration.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_configuration.ipynb <plot_logging_configuration.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_logging_configuration.py <plot_logging_configuration.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_logging_configuration.zip <plot_logging_configuration.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
