Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork937
Description
This issue should not be confused with what the change in#1807 is trying to improve. The outcome of that PR is unrelated to this issue, because GitPython itself useslogging.NullHandler
notgit.util.NullHandler
.
Although therecommended default behavior for libraries is to allow messages ofWARNING
or higher severity to be displayed when the calling code does not configure logging, a library also has the option of causing its messages to be suppressed by default by registering an instance ofNullHandler
as a handler. (Logging is still happening; messages can still be subscribed to by the addition of other handlers.) GitPython takes this approach, though in a bit of a different way the Python documentation suggests for it. In GitPython,NullHandler
s are registered for the individual modules' loggers rather than for a library-wide "top-level" logger.
This is with one exception.git.repo.base
does not register aNullHandler
:
(.venv) ek@Glub:~/repos-wsl/GitPython (main $=)$ git grep -Fn NullHandler -- git/git/cmd.py:85:log.addHandler(logging.NullHandler())git/config.py:65:log.addHandler(logging.NullHandler())git/objects/commit.py:56:log.addHandler(logging.NullHandler())git/objects/submodule/base.py:60:log.addHandler(logging.NullHandler())git/objects/submodule/root.py:26:log.addHandler(logging.NullHandler())git/remote.py:69:log.addHandler(logging.NullHandler())git/util.py:1297:class NullHandler(logging.Handler):(.venv) ek@Glub:~/repos-wsl/GitPython (main $=)$ git grep -Fn logging.getLogger -- git/git/cmd.py:84:log = logging.getLogger(__name__)git/config.py:64:log = logging.getLogger("git.config")git/objects/commit.py:55:log = logging.getLogger("git.objects.commit")git/objects/submodule/base.py:59:log = logging.getLogger("git.objects.submodule.base")git/objects/submodule/root.py:25:log = logging.getLogger("git.objects.submodule.root")git/remote.py:68:log = logging.getLogger("git.remote")git/repo/base.py:92:log = logging.getLogger(__name__)git/util.py:107:log = logging.getLogger(__name__)
It is unclear if this is intentional. It is easy to miss one (see#666) so it may well be an unintended omission.
I believe one of the following changes should be made, but I do not know which:
- State in a comment (or docstring) in
git.repo.base
why its logger is special. - Register a
NullHandler
for thegit.repo.base
logger. - Stop registering
NullHandler
s for the other loggers.
I am not sure if causing messages from GitPython, even ofWARNING
and higher severity, not to appear by default is actually considered desirable. TheNullHandler
s were introduced in#300. At that time, this was not with the goal of suppressing messages, but instead to avoid "No handlers could be found for logger" errors. It is no longer necessary to do thatsince Python 3.2. So if the only reason is as given in#300 and suppressing messages is not itself a goal, then theNullHandler
s should be removed, unless it is considered important to keep them for compatibility with previous expected behavior of GitPython.
Other than the first approach of adding a comment, any changes could be inconvenient to developers of programs or other libraries that use GitPython, and to users of such software. I am unsure if they could reasonably be considered breaking. I am inclined to think that most such changes would be non-breaking but still should not be undertaken without carefully considering the impact on users and developers who may expect the current behavior.