scottrogowski / code2flow

Pretty good call graphs for dynamic languages
MIT License
3.92k stars 286 forks source link

code2flow changes configuration of loggers #95

Open maxjeblick opened 6 months ago

maxjeblick commented 6 months ago

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.

pawamoy commented 2 months ago

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

pawamoy commented 2 months ago

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") :slightly_smiling_face:

pawamoy commented 2 months ago

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

from unittest.mock import MagicMock
from code2flow import engine

engine.logging = MagicMock()
maxjeblick commented 1 month ago

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