Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging should use named logger rather than root logger #240

Closed
heikoklein opened this issue Apr 13, 2022 · 1 comment
Closed

logging should use named logger rather than root logger #240

heikoklein opened this issue Apr 13, 2022 · 1 comment

Comments

@heikoklein
Copy link

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

@karimbahgat
Copy link
Collaborator

I had a small note in the docs to toggle the warnings by setting the module VERBOSE constant to False, but updated the README to make this more clear. In addition I switched to your suggested solution of using a named logger. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants