File tree 4 files changed +60
-1
lines changed
4 files changed +60
-1
lines changed Original file line number Diff line number Diff line change 19
19
import warnings
20
20
from typing import Any
21
21
22
+ import gitlab ._logging
22
23
import gitlab .config # noqa: F401
23
24
from gitlab import utils as _utils
24
25
from gitlab ._version import ( # noqa: F401
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ The initialization of the logging module is intentionaly done here in the
4
+ _logging.py module so that it will be initialized before any other of our
5
+ python-gitlab modules are loaded. So if they do logging upon being loaded it
6
+ will allow them to do it safely.
7
+ """
8
+
9
+ # This program is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU Lesser General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # This program is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU Lesser General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU Lesser General Public License
20
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
21
+
22
+ import logging
23
+ from typing import List
24
+
25
+ __all__ : List [str ] = []
26
+
27
+ # Using the `NullHandler` means that any log messages generated will not be
28
+ # output unless the client application configures logging. For example by
29
+ # calling `logging.basicConfig()`
30
+ _module_root_logger_name = __name__ .split ("." , maxsplit = 1 )[0 ]
31
+ logging .getLogger (_module_root_logger_name ).addHandler (logging .NullHandler ())
Original file line number Diff line number Diff line change 1
1
"""Wrapper for the GitLab API."""
2
2
3
+ import logging
3
4
import os
4
5
import re
5
6
import time
14
15
import gitlab .exceptions
15
16
from gitlab import _backends , utils
16
17
18
+ LOG = logging .getLogger (__name__ )
19
+
17
20
REDIRECT_MSG = (
18
21
"python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
19
22
"your GitLab URL to the correct URL to avoid issues. The redirection was from: "
@@ -540,7 +543,6 @@ def _set_auth_info(self) -> None:
540
543
541
544
@staticmethod
542
545
def enable_debug () -> None :
543
- import logging
544
546
from http .client import HTTPConnection # noqa
545
547
546
548
HTTPConnection .debuglevel = 1
@@ -549,6 +551,7 @@ def enable_debug() -> None:
549
551
requests_log = logging .getLogger ("requests.packages.urllib3" )
550
552
requests_log .setLevel (logging .DEBUG )
551
553
requests_log .propagate = True
554
+ LOG .debug ("Enabled debug mode for python-gitlab" )
552
555
553
556
def _get_session_opts (self ) -> Dict [str , Any ]:
554
557
return {
Original file line number Diff line number Diff line change
1
+ import logging
2
+
3
+ import pytest
4
+
5
+ from gitlab import _logging
6
+
7
+
8
+ @pytest .fixture
9
+ def LOG ():
10
+ return logging .getLogger (_logging ._module_root_logger_name )
11
+
12
+
13
+ def test_module_root_logger_name ():
14
+ assert _logging ._module_root_logger_name == "gitlab"
15
+
16
+
17
+ def test_module_name (LOG ):
18
+ assert LOG .name == "gitlab"
19
+
20
+
21
+ def test_logger_null_handler (LOG ):
22
+ assert len (LOG .handlers ) == 1
23
+ handler = LOG .handlers [0 ]
24
+ assert isinstance (handler , logging .NullHandler )
You can’t perform that action at this time.
0 commit comments