Skip to content

Commit 48b9ed9

Browse files
committed
address PR feedback
1 parent 7b1605c commit 48b9ed9

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

google/api_core/client_logging.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44
import os
55

6-
LOGGING_INITIALIZED = False
6+
_LOGGING_INITIALIZED = False
77

88
# TODO(<add-link>): Update Request / Response messages.
99
REQUEST_MESSAGE = "Sending request ..."
@@ -13,15 +13,15 @@
1313
_recognized_logging_fields = ["httpRequest", "rpcName", "serviceName"] # Additional fields to be Logged.
1414

1515
def logger_configured(logger):
16-
return logger.hasHandlers() or logger.level != logging.NOTSET
16+
return logger.hasHandlers() or logger.level != logging.NOTSET or logger.propagate == False
1717

1818
def initialize_logging():
19-
global LOGGING_INITIALIZED
20-
if LOGGING_INITIALIZED:
19+
global _LOGGING_INITIALIZED
20+
if _LOGGING_INITIALIZED:
2121
return
2222
scopes = os.getenv("GOOGLE_SDK_PYTHON_LOGGING_SCOPE")
2323
setup_logging(scopes)
24-
LOGGING_INITIALIZED = True
24+
_LOGGING_INITIALIZED = True
2525

2626
def parse_logging_scopes(scopes):
2727
if not scopes:
@@ -31,7 +31,7 @@ def parse_logging_scopes(scopes):
3131
namespaces = [scopes]
3232
return namespaces
3333

34-
def default_settings(logger):
34+
def configure_defaults(logger):
3535
if not logger_configured(logger):
3636
console_handler = logging.StreamHandler()
3737
logger.setLevel("DEBUG")
@@ -54,8 +54,8 @@ def setup_logging(scopes):
5454
# This will either create a module level logger or get the reference of the base logger instantiated above.
5555
logger = logging.getLogger(namespace)
5656

57-
# Set default settings.
58-
default_settings(logger)
57+
# Configure default settings.
58+
configure_defaults(logger)
5959

6060
class StructuredLogFormatter(logging.Formatter):
6161
def format(self, record):

tests/unit/test_client_logging.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import logging
22
import pytest
33

4-
from google.api_core.client_logging import BaseLogger
4+
# Test expected behaviour for warnings, propagation, handler + formatter.
55

6+
def test_setup_logging_w_no_scopes():
7+
# TODO(in-progress):
8+
pass
69

7-
def test_base_logger(caplog):
10+
def test_setup_logging_w_base_scope():
11+
# TODO(in-progress):
12+
pass
813

9-
logger = BaseLogger().get_logger()
14+
def test_setup_logging_w_module_scope():
15+
# TODO(in-progress):
16+
pass
1017

11-
with caplog.at_level(logging.INFO, logger="google"):
12-
logger.info("This is a test message.")
13-
14-
assert "This is a test message." in caplog.text
15-
assert caplog.records[0].name == "google"
16-
assert caplog.records[0].levelname == "INFO"
17-
assert caplog.records[0].message == "This is a test message."
18+
def test_setup_logging_w_incorrect_scope():
19+
# TODO(in-progress):
20+
pass

0 commit comments

Comments
 (0)