-
Notifications
You must be signed in to change notification settings - Fork 33
Description
Hey folks I'm working over at https://github.com/daniel-j-h/meshcore-irc-bridge with your awesome meshcore_py library.
I noticed that we call
meshcore_py/src/meshcore/__init__.py
Line 13 in e518381
| logging.basicConfig(level=logging.INFO) |
this configures the root logger for any app that imports this library. In my case for example it configures my app's logger and overwrites and hard codes its behavior.
The second problem seems to be setting the levels in
meshcore_py/src/meshcore/meshcore.py
Lines 43 to 48 in e518381
| if debug: | |
| logger.setLevel(logging.DEBUG) | |
| elif only_error: | |
| logger.setLevel(logging.ERROR) | |
| else: | |
| logger.setLevel(logging.INFO) |
but this less of a problem.
What I propose: the python idiomatic way for a library to set up logging seem to be
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler()) # if needed to prevent warnings
and to let apps importing this lib configure their logging like this
logging.basicConfig(level=logging.INFO)
logging.getLogger("meshcore").setLevel(logging.DEBUG)
This would make your awesome library a better citizen with apps where logging is already configured.
refs