lazy_import icon indicating copy to clipboard operation
lazy_import copied to clipboard

lazy_module breaks logging

Open emsi opened this issue 6 years ago • 3 comments

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.

emsi avatar Oct 10 '18 14:10 emsi

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.

smerkousdavid avatar Mar 27 '19 03:03 smerkousdavid

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

image357 avatar Jul 03 '20 16:07 image357

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

kunom avatar Jun 09 '21 06:06 kunom