Skip to content

Commit 9943da9

Browse files
authored
fix(Logging): Expand APPLICATION_LOGGERS and fix unnamed loggers (#7256)
1 parent 8f6f111 commit 9943da9

12 files changed

Lines changed: 24 additions & 70 deletions

File tree

api/conftest.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import logging
21
import os
32
import site
43
import typing
@@ -1253,23 +1252,6 @@ def superuser_client(superuser: FFAdminUser, client: APIClient): # type: ignore
12531252
return client
12541253

12551254

1256-
@pytest.fixture
1257-
def inspecting_handler() -> logging.Handler:
1258-
"""
1259-
Fixture used to test the output of logger related output.
1260-
"""
1261-
1262-
class InspectingHandler(logging.Handler):
1263-
def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def]
1264-
super().__init__(*args, **kwargs)
1265-
self.messages = [] # type: ignore[var-annotated]
1266-
1267-
def handle(self, record: logging.LogRecord) -> None: # type: ignore[override]
1268-
self.messages.append(self.format(record))
1269-
1270-
return InspectingHandler()
1271-
1272-
12731255
@pytest.fixture
12741256
def set_github_webhook_secret() -> None:
12751257
from django.conf import settings

api/edge_api/identities/export.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
EXPORT_EDGE_IDENTITY_PAGINATION_LIMIT = 20000
1515

16-
logger = logging.getLogger()
16+
logger = logging.getLogger(__name__)
1717

1818

1919
def export_edge_identity_and_overrides( # noqa: C901

api/edge_api/management/commands/ensure_identity_traits_blanks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
identity_wrapper = DynamoIdentityWrapper()
1111

12-
logger: structlog.BoundLogger = structlog.get_logger()
12+
logger: structlog.BoundLogger = structlog.get_logger(__name__)
1313

1414
LOG_COUNT_EVERY = 100_000
1515

api/environments/dynamodb/wrappers/identity_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
from environments.identities.models import Identity
3333

34-
logger = logging.getLogger()
34+
logger = logging.getLogger(__name__)
3535

3636

3737
class DynamoIdentityWrapper(BaseDynamoWrapper):

api/features/views.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@
110110
get_environment_flags_queryset,
111111
)
112112

113-
logger = logging.getLogger()
114-
logger.setLevel(logging.INFO)
113+
logger = logging.getLogger(__name__)
115114

116115
flags_cache = caches[settings.FLAGS_CACHE_LOCATION]
117116

api/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ addopts = [
7676
'--dist=worksteal',
7777
]
7878
console_output_style = 'count'
79+
log_level = 'INFO'
7980

8081
[tool.mypy]
8182
plugins = ["mypy_django_plugin.main"]

api/scripts/run-docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33

44
# common environment variables
55
ACCESS_LOG_FORMAT=${ACCESS_LOG_FORMAT:-'%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" %({origin}i)s %({access-control-allow-origin}o)s'}
6-
APPLICATION_LOGGERS=${APPLICATION_LOGGERS:-"common,features,task_processor,app_analytics,webhooks"}
6+
APPLICATION_LOGGERS=${APPLICATION_LOGGERS:-"app_analytics,audit,code_references,common,core,dynamodb,edge_api,environments,features,import_export,integrations,oauth2_metadata,organisations,projects,segments,task_processor,users,webhooks,workflows"}
77

88
waitfordb() {
99
if [ -z "${SKIP_WAIT_FOR_DB}" ]; then

api/segments/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from projects.models import Project
1212
from segments.models import Condition, Segment, SegmentRule
1313

14-
logger = structlog.get_logger()
14+
logger = structlog.get_logger(__name__)
1515

1616
DictList = list[dict[str, Any]]
1717

api/segments/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
if TYPE_CHECKING:
3636
from users.models import FFAdminUser
3737

38-
logger = logging.getLogger()
38+
logger = logging.getLogger(__name__)
3939

4040

4141
@method_decorator(

api/tests/unit/integrations/lead_tracking/hubspot/test_unit_hubspot_client.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import logging
32
import typing
43

54
import pytest
@@ -120,13 +119,9 @@ def test_create_lead_form__valid_user_data__submits_form_successfully(
120119
def test_create_lead_form__api_returns_error__logs_error(
121120
staff_user: FFAdminUser,
122121
hubspot_client: HubspotClient,
123-
inspecting_handler: logging.Handler,
122+
caplog: pytest.LogCaptureFixture,
124123
) -> None:
125124
# Given
126-
from integrations.lead_tracking.hubspot.client import logger
127-
128-
logger.addHandler(inspecting_handler)
129-
130125
hubspot_cookie = "test_hubspot_cookie"
131126
url = f"{HUBSPOT_ROOT_FORM_URL}/{HUBSPOT_PORTAL_ID}/{HUBSPOT_FORM_ID_SAAS}"
132127
responses.add(
@@ -141,7 +136,7 @@ def test_create_lead_form__api_returns_error__logs_error(
141136

142137
# Then
143138
assert response == {"error": "Problem processing."}
144-
assert inspecting_handler.messages == [ # type: ignore[attr-defined]
139+
assert caplog.messages == [
145140
"Creating Hubspot lead form for user staff@example.com with hubspot cookie test_hubspot_cookie",
146141
"Problem posting data to Hubspot's form API due to 400 status code and following response: "
147142
+ '{"error": "Problem processing."}',

0 commit comments

Comments
 (0)