mnmelo/lazy_import

lazy_module breaks logging

emsi opened this issue · 3 comments

emsi commented

lazy_module changes root logger and thus affects programs importing it in undesired way.
The following snippet illustrates the issue:

import lazy_import
import logging

if __name__ == '__main__':
    logger = logging.getLogger('dupa')

    logging.basicConfig(
        format='%(asctime)s ai [%(process)d] <%(levelname)s> '
               '| %(module)s | %(processName)s | %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S',
        level=logging.DEBUG
    )

    logger.info('DUPA')

Removing the import lazy_import restores desired default behavior.

lazy_import should use its own logger and refrain from calling logging.basicConfig().

As per https://docs.python.org/3/library/logging.html#logging.basicConfig

This function does nothing if the root logger already has handlers configured for it.

I totally agree with @emsi. Also, I would stay away from loading the version from another file because it's an unnecessary load which breaks when it comes to packing like pyinstaller. A lot of the default python features and basic practices should be removed from the package to not break things like logging or optimized packaging.

@emsi @smerkousdavid @mnmelo
Confirmed. Opened PR #21 to fix

kunom commented

I was also hit by this. I guess it is bad behavior of a library to setup/configure the global logging setup.