Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazy_module breaks logging #8

Open
emsi opened this issue Oct 10, 2018 · 3 comments
Open

lazy_module breaks logging #8

emsi opened this issue Oct 10, 2018 · 3 comments

Comments

@emsi
Copy link

emsi commented Oct 10, 2018

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 emsi changed the title lazy_module break default logging lazy_module breaks logging Oct 10, 2018
@smerkousdavid
Copy link

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.

@image357
Copy link

image357 commented Jul 3, 2020

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

@kunom
Copy link

kunom commented Jun 9, 2021

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

mkorvas pushed a commit to mkorvas/deduce that referenced this issue Aug 9, 2024
Logging needs be configured by application code, while
Deduce is a library (to be imported, not to be run).

Reminiscent of mnmelo/lazy_import#8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants