Skip to content

Commit 69bbd05

Browse files
committed
add coverage for already configured scope
1 parent 601b653 commit 69bbd05

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

google/api_core/client_logging.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
] # Additional fields to be Logged.
1616

1717

18+
# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation.
1819
def logger_configured(logger):
1920
return (
2021
logger.handlers != [] or logger.level != logging.NOTSET or not logger.propagate
2122
)
2223

2324

25+
# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation.
2426
def initialize_logging():
2527
global _LOGGING_INITIALIZED
2628
if _LOGGING_INITIALIZED:
@@ -30,6 +32,7 @@ def initialize_logging():
3032
_LOGGING_INITIALIZED = True
3133

3234

35+
# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation.
3336
def parse_logging_scopes(scopes: Optional[str] = None) -> List[str]:
3437
if not scopes:
3538
return []
@@ -40,6 +43,7 @@ def parse_logging_scopes(scopes: Optional[str] = None) -> List[str]:
4043
return namespaces
4144

4245

46+
# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation.
4347
def configure_defaults(logger):
4448
if not logger_configured(logger):
4549
console_handler = logging.StreamHandler()
@@ -50,6 +54,7 @@ def configure_defaults(logger):
5054
logger.addHandler(console_handler)
5155

5256

57+
# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation.
5358
def setup_logging(scopes=""):
5459

5560
# only returns valid logger scopes (namespaces)
@@ -69,6 +74,7 @@ def setup_logging(scopes=""):
6974
base_logger.propagate = False
7075

7176

77+
# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation.
7278
class StructuredLogFormatter(logging.Formatter):
7379
# TODO(https://github.com/googleapis/python-api-core/issues/761): ensure that additional fields such as
7480
# function name, file name, and line no. appear in a log output.

tests/unit/test_client_logging.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ def test_setup_logging_w_base_scope():
3838
reset_logger("foo")
3939

4040

41+
def test_setup_logging_w_configured_scope():
42+
with mock.patch("google.api_core.client_logging._BASE_LOGGER_NAME", "foo"):
43+
base_logger = logging.getLogger("foo")
44+
base_logger.propagate = False
45+
setup_logging("foo")
46+
assert base_logger.handlers == []
47+
assert not base_logger.propagate
48+
assert base_logger.level == logging.NOTSET
49+
50+
reset_logger("foo")
51+
52+
4153
def test_setup_logging_w_module_scope():
4254
with mock.patch("google.api_core.client_logging._BASE_LOGGER_NAME", "foo"):
4355
setup_logging("foo.bar")

0 commit comments

Comments
 (0)