Skip to content

logging should use named logger rather than root logger #240

Closed
@heikoklein

Description

@heikoklein

Hi,
I'm plotting maps with cartopy and use the GSHHS maps as background. From there I get warnings like:
WARNING:root:Possible issue encountered when converting Shape #95 to GeoJSON: Shapefile format requires that polygons contain at least one exterior ring, but the Shape was entirely made up of interior holes (defined by counter-clockwise orientation in the shapefile format). The rings were still included but were encoded as GeoJSON exterior rings instead of holes.

After some search I found out that these warnings are from shapefile.py, which uses the root-logger as logger.warning whenever a problem occurs. Currently, I have to suppress the root-logger to suppress the warning, i.e.

logging.root.setLevel(logging.ERROR)

As a library, it would make the users life easier if a named logger rather than the root logger would be used as suggested by the logging documentation:

A good convention to use when naming loggers is to use a module-level logger, in each module which uses logging, named as follows:

logger = logging.getLogger(__name__)
...
logger.warning(msg)

Then a user (or the GSHHS library provider) could suppress the specific warnings as logging.getLogger('shapefile').setLevel(logging.ERROR)

Best regards,
Heiko

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions