Pvlib-python: logging.basicConfig in __init__.py causes misbehavior after import

Created on 5 Apr 2018  路  4Comments  路  Source: pvlib/pvlib-python

Since basicConfig is called as a import side-effect of pvlib, any software that imports anything from pvlib can not use it's own basicConfig (if basicConfig was already called, any further call just does nothing - not even giving a warning).

This leads to unexpected behavior (no more debug output) which is rather hard to track down.

I don't know whether it is bad to copy issues word-by-word, but this affects pvlib as well: https://github.com/circus-tent/circus/issues/826

The problem can be reproduced using the code form Python logging cookbook:
https://docs.python.org/2/howto/logging-cookbook.html#using-logging-in-multiple-modules
Adding import pvlib will cause all logging to be ouputted to terminal.

Maybe this is by design, but it's a bit difficult to get around.

api bug

Most helpful comment

@mikofski, Thank You for the suggestion. Weird enough, setting logger.propagate = False worked great even when only set in the examples main.py file. The auxiliary module didn't need the propagate-property to be set.

I dare not say anything about pvlib's logging requirements, as I'm only working with it indirectly.

All 4 comments

I think all logging in pvlib can be removed, with maybe a couple of calls being replaced with warnings. Most pvlib logging is a holdover from my early efforts to remove print and some debugging.

@Gemmu if you set propagate to False then it shouldn't inherit the root logger.

@wholmgren instead of using basicConfig create a pvlib logger that has it's own handlers and formatters so it doesn't propagate. See the HOWTO on configuring loggers or the logging cookbook

@mikofski sure, but I don't think pvlib should be logging anything. Do you find pvlib logging to be useful? I think issuing warnings and pushing developers towards pdb is more appropriate for the vast majority of the existing logging calls.

@mikofski, Thank You for the suggestion. Weird enough, setting logger.propagate = False worked great even when only set in the examples main.py file. The auxiliary module didn't need the propagate-property to be set.

I dare not say anything about pvlib's logging requirements, as I'm only working with it indirectly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KonstantinTr picture KonstantinTr  路  7Comments

mikofski picture mikofski  路  5Comments

wholmgren picture wholmgren  路  5Comments

wholmgren picture wholmgren  路  6Comments

Jawairia123 picture Jawairia123  路  6Comments