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

code2flow changes configuration of loggers #95

Open
maxjeblick opened this issue Mar 13, 2024 · 4 comments · May be fixed by #97
Open

code2flow changes configuration of loggers #95

maxjeblick opened this issue Mar 13, 2024 · 4 comments · May be fixed by #97

Comments

@maxjeblick
Copy link

When calling code2flow within python (i.e. not via cmd line), the default logging config is overwritten:
logging.basicConfig(format="Code2Flow: %(message)s", level=level)

This is a bit annoying, as it requires to reconfigure logging after calling code2flow to remove Code2Flow prefix.

d3dave added a commit to d3dave/code2flow that referenced this issue May 8, 2024
d3dave added a commit to d3dave/code2flow that referenced this issue May 8, 2024
@d3dave d3dave linked a pull request Jun 14, 2024 that will close this issue
@pawamoy
Copy link

pawamoy commented Jul 12, 2024

Yep, agree. Code2Flow should only call logging.basicConfig() from its main entrypoint, not from the code2flow function, which is documented as programmatic use.

@pawamoy
Copy link

pawamoy commented Jul 12, 2024

Oh, worse than that, it uses the root logger, so we can't even disable logging for code2flow only with something like this:

logging.getLogger("code2flow").setLevel(logging.CRITICAL + 1)

Code2Flow should get its own logger with logger = logging.getLogger("code2flow") 🙂

@pawamoy
Copy link

pawamoy commented Jul 12, 2024

I was able to disable code2flow.engine's logging with this:

from unittest.mock import MagicMock
from code2flow import engine

engine.logging = MagicMock()

@maxjeblick
Copy link
Author

I implemeted a similar fix using mock.patch.object contextmanager
https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/sorters/code2flow_patched.py#L25

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

Successfully merging a pull request may close this issue.

2 participants