diff --git a/google/api_core/client_logging.py b/google/api_core/client_logging.py index bc80e52b..a9693531 100644 --- a/google/api_core/client_logging.py +++ b/google/api_core/client_logging.py @@ -15,12 +15,14 @@ ] # Additional fields to be Logged. +# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation. def logger_configured(logger): return ( logger.handlers != [] or logger.level != logging.NOTSET or not logger.propagate ) +# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation. def initialize_logging(): global _LOGGING_INITIALIZED if _LOGGING_INITIALIZED: @@ -30,6 +32,7 @@ def initialize_logging(): _LOGGING_INITIALIZED = True +# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation. def parse_logging_scopes(scopes: Optional[str] = None) -> List[str]: if not scopes: return [] @@ -40,6 +43,7 @@ def parse_logging_scopes(scopes: Optional[str] = None) -> List[str]: return namespaces +# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation. def configure_defaults(logger): if not logger_configured(logger): console_handler = logging.StreamHandler() @@ -50,6 +54,7 @@ def configure_defaults(logger): logger.addHandler(console_handler) +# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation. def setup_logging(scopes=""): # only returns valid logger scopes (namespaces) @@ -69,6 +74,7 @@ def setup_logging(scopes=""): base_logger.propagate = False +# TODO(https://github.com/googleapis/python-api-core/issues/763): Add documentation. class StructuredLogFormatter(logging.Formatter): # TODO(https://github.com/googleapis/python-api-core/issues/761): ensure that additional fields such as # function name, file name, and line no. appear in a log output. diff --git a/tests/unit/test_client_logging.py b/tests/unit/test_client_logging.py index b2467037..48808b48 100644 --- a/tests/unit/test_client_logging.py +++ b/tests/unit/test_client_logging.py @@ -38,6 +38,18 @@ def test_setup_logging_w_base_scope(): reset_logger("foo") +def test_setup_logging_w_configured_scope(): + with mock.patch("google.api_core.client_logging._BASE_LOGGER_NAME", "foo"): + base_logger = logging.getLogger("foo") + base_logger.propagate = False + setup_logging("foo") + assert base_logger.handlers == [] + assert not base_logger.propagate + assert base_logger.level == logging.NOTSET + + reset_logger("foo") + + def test_setup_logging_w_module_scope(): with mock.patch("google.api_core.client_logging._BASE_LOGGER_NAME", "foo"): setup_logging("foo.bar")