File: errors.rst

package info (click to toggle)
rasterio 1.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 22,744 kB
  • sloc: python: 22,881; sh: 795; makefile: 275; xml: 29
file content (57 lines) | stat: -rw-r--r-- 1,419 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Error Handling
==============

.. todo::

    error enums, context managers, converting GDAL errors to python exceptions


Debugging internal GDAL functions
----------------------------------

To get more debugging information from the internal GDAL/PROJ code:

1. Enable the `CPL_DEBUG` config option.

    .. note:: If setting the :envvar:`PROJ_DEBUG` environment variable
              inside a Python script, make sure that it is set before
              importing rasterio.

    .. code-block:: python

        import os
        os.environ["PROJ_DEBUG"] = "2"

        import rasterio

        with rasterio.Env(CPL_DEBUG=True):
            ...


2. Activate logging in `rasterio` with the devel `DEBUG`:

    More information available here: https://docs.python.org/3/howto/logging.html

    Here are examples to get started.

    Example - Add handler to the `rasterio` logger:

    .. code-block:: python

        import logging

        console_handler = logging.StreamHandler()
        formatter = logging.Formatter("%(levelname)s:%(message)s")
        console_handler.setFormatter(formatter)
        logger = logging.getLogger("rasterio")
        logger.addHandler(console_handler)
        logger.setLevel(logging.DEBUG)


    Example - Activate default logging config:

    .. code-block:: python

        import logging

        logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.DEBUG)