Skip to content

Logger should not be changed at module level

Most modules seem to contain the following lines (at the module level):

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())

The logger should not be updated at the module level. i.e. importing a module should not update the logging configuration.

In your app you can simply call (in the main section - it shouldn't really be anywhere else):

logging.basicConfig(level='DEBUG')

Or to just set everything within entrezpy to DEBUG:

logging.basicConfig(level='INFO')
logging.getLogger('entrezpy').setLevel('DEBUG')

And it would have the equivalent effect.

When used as a library, it would respect the logging configuration that was setup there.

Edited by jpb