diff options
author | John L. Villalovos <john@sodarock.com> | 2022-10-03 21:29:54 -0700 |
---|---|---|
committer | Nejc Habjan <nejc.habjan@siemens.com> | 2023-03-12 20:23:40 +0100 |
commit | b476afe9928c6e844b86b56f9316ae1a1fe254f2 (patch) | |
tree | 8aa4e2743dacd661365d04bdfedf8477626d6fce /gitlab/client.py | |
parent | 7a8a86278543a1419d07dd022196e4cb3db12d31 (diff) | |
download | gitlab-jlvillal/logging.tar.gz |
chore: add bare-minimum logging supportjlvillal/logging
Follow the Python documentation guidelines for "Configuring Logging
for a Library" [1]
Which is basically adding these two lines:
import logging
logging.getLogger(__name__).addHandler(logging.NullHandler())
Setup a very basic usage of logging in `gitlab/client.py`
By using the NullHandler it means that by default any log messages
output will not be displayed. It is up to the client application to do
a `logging.basicConfig()` call to get log messages to display.
[1] https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
Related: #2080
Diffstat (limited to 'gitlab/client.py')
-rw-r--r-- | gitlab/client.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/gitlab/client.py b/gitlab/client.py index 94fb66a..3b1e49b 100644 --- a/gitlab/client.py +++ b/gitlab/client.py @@ -1,5 +1,6 @@ """Wrapper for the GitLab API.""" +import logging import os import re import time @@ -14,6 +15,8 @@ import gitlab.const import gitlab.exceptions from gitlab import _backends, utils +LOG = logging.getLogger(__name__) + REDIRECT_MSG = ( "python-gitlab detected a {status_code} ({reason!r}) redirection. You must update " "your GitLab URL to the correct URL to avoid issues. The redirection was from: " @@ -540,7 +543,6 @@ class Gitlab: @staticmethod def enable_debug() -> None: - import logging from http.client import HTTPConnection # noqa HTTPConnection.debuglevel = 1 @@ -549,6 +551,7 @@ class Gitlab: requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True + LOG.debug("Enabled debug mode for python-gitlab") def _get_session_opts(self) -> Dict[str, Any]: return { |