Skip to content

Commit

Permalink
config: Setup JSON log for DataDog
Browse files Browse the repository at this point in the history
  • Loading branch information
rsebille committed Mar 7, 2025
1 parent e24c9f6 commit c911349
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 deletions.
31 changes: 31 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,46 @@
]

MIDDLEWARE = [
# Generate request Id
"django_datadog_logger.middleware.request_id.RequestIdMiddleware",
# Django stack
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
# Final logger
"django_datadog_logger.middleware.request_log.RequestLoggingMiddleware",
]

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
# "console": {"format": "{levelname} {message}", "style": "{"},
"json": {"()": "django_datadog_logger.formatters.datadog.DataDogJSONFormatter"},
},
"handlers": {
"console": {"class": "logging.StreamHandler", "formatter": "json"},
"null": {"class": "logging.NullHandler"},
},
"loggers": {
"": {"handlers": ["console"], "level": "INFO"},
"django": {
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
},
"django.security.DisallowedHost": {
"handlers": ["null"],
"propagate": False,
},
"pilotage": {
"level": os.getenv("PILOTAGE_LOG_LEVEL", "INFO"),
},
},
}

ROOT_URLCONF = "config.urls"

TEMPLATES = [
Expand Down
3 changes: 3 additions & 0 deletions config/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"] # noqa F405

# Don't use json formatter in dev
del LOGGING["handlers"]["console"]["formatter"] # noqa: F405

DATABASES["default"]["HOST"] = os.getenv("PGHOST", "127.0.0.1") # noqa: F405
DATABASES["default"]["PORT"] = os.getenv("PGPORT", "5433") # noqa: F405
DATABASES["default"]["NAME"] = os.getenv("PGDATABASE", "pilotage_django") # noqa: F405
Expand Down
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ psycopg[binary] # https://github.com/psycopg/psycopg

Django==5.1.* # https://www.djangoproject.com/
django-compressor # https://django-compressor.readthedocs.io/en/latest/
django-datadog-logger # https://github.com/namespace-ee/django-datadog-logger
django-libsass # https://github.com/torchbox/django-libsass

# Third-party applications
Expand Down
17 changes: 13 additions & 4 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ django==5.1.6 \
# -r requirements/base.in
# django-appconf
# django-compressor
# django-datadog-logger
# djangorestframework
django-appconf==1.1.0 \
--hash=sha256:7abd5a163ff57557f216e84d3ce9dac36c37ffce1ab9a044d3d53b7c943dd10f \
--hash=sha256:9fcead372f82a0f21ee189434e7ae9c007cbb29af1118c18251720f3d06243e4
Expand All @@ -21,10 +23,21 @@ django-compressor==4.5.1 \
# via
# -r requirements/base.in
# django-libsass
django-datadog-logger==0.7.3 \
--hash=sha256:4361bb068a4b188fa14135398f9b747728464a291757e6adf8c95c9215dcd602 \
--hash=sha256:87838cd868f407e050831c536413de6b2ece31433b28c952c0fd90be1d66486a
# via -r requirements/base.in
django-libsass==0.9 \
--hash=sha256:5234d29100889cac79e36a0f44207ec6d275adfd2da1acb6a94b55c89fe2bd97 \
--hash=sha256:bfbbb55a8950bb40fa04dd416605f92da34ad1f303b10a41abc3232386ec27b5
# via -r requirements/base.in
djangorestframework==3.15.2 \
--hash=sha256:2b8871b062ba1aefc2de01f773875441a961fefbf79f5eed1e32b2f096944b20 \
--hash=sha256:36fe88cd2d6c6bec23dca9804bab2ba5517a8bb9d8f47ebc68981b56840107ad
# via django-datadog-logger
json-log-formatter==1.1.1 \
--hash=sha256:0815e3b4469e5c79cf3f6dc8a0613ba6601f4a7464f85ba03655cfa6e3e17d10
# via django-datadog-logger
libsass==0.23.0 \
--hash=sha256:31e86d92a5c7a551df844b72d83fc2b5e50abc6fbbb31e296f7bebd6489ed1b4 \
--hash=sha256:34cae047cbbfc4ffa832a61cbb110f3c95f5471c6170c842d3fed161e40814dc \
Expand Down Expand Up @@ -214,7 +227,3 @@ sqlparse==0.5.3 \
--hash=sha256:09f67787f56a0b16ecdbde1bfc7f5d9c3371ca683cfeaa8e6ff60b4807ec9272 \
--hash=sha256:cf2196ed3418f3ba5de6af7e82c694a9fbdbfecccdfc72e281548517081f16ca
# via django
typing-extensions==4.12.2 \
--hash=sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d \
--hash=sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8
# via psycopg
21 changes: 17 additions & 4 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ django==5.1.6 \
# -r requirements/base.txt
# django-appconf
# django-compressor
# django-datadog-logger
# django-debug-toolbar
# djangorestframework
django-appconf==1.1.0 \
--hash=sha256:7abd5a163ff57557f216e84d3ce9dac36c37ffce1ab9a044d3d53b7c943dd10f \
--hash=sha256:9fcead372f82a0f21ee189434e7ae9c007cbb29af1118c18251720f3d06243e4
Expand All @@ -38,6 +40,10 @@ django-compressor==4.5.1 \
# via
# -r requirements/base.txt
# django-libsass
django-datadog-logger==0.7.3 \
--hash=sha256:4361bb068a4b188fa14135398f9b747728464a291757e6adf8c95c9215dcd602 \
--hash=sha256:87838cd868f407e050831c536413de6b2ece31433b28c952c0fd90be1d66486a
# via -r requirements/base.txt
django-debug-toolbar==5.0.1 \
--hash=sha256:296f6f18a80710e84fbb8361538ae5ec522a75ebe9ab67db34bcf1026cbeb420 \
--hash=sha256:7456cc2e951db37dab335686db7803c4a0ecb6736d120705f6668db9548bf49f
Expand All @@ -46,6 +52,12 @@ django-libsass==0.9 \
--hash=sha256:5234d29100889cac79e36a0f44207ec6d275adfd2da1acb6a94b55c89fe2bd97 \
--hash=sha256:bfbbb55a8950bb40fa04dd416605f92da34ad1f303b10a41abc3232386ec27b5
# via -r requirements/base.txt
djangorestframework==3.15.2 \
--hash=sha256:2b8871b062ba1aefc2de01f773875441a961fefbf79f5eed1e32b2f096944b20 \
--hash=sha256:36fe88cd2d6c6bec23dca9804bab2ba5517a8bb9d8f47ebc68981b56840107ad
# via
# -r requirements/base.txt
# django-datadog-logger
djlint==1.36.4 \
--hash=sha256:16ce37e085afe5a30953b2bd87cbe34c37843d94c701fc68a2dda06c1e428ff4 \
--hash=sha256:17254f218b46fe5a714b224c85074c099bcb74e3b2e1f15c2ddc2cf415a408a1 \
Expand Down Expand Up @@ -82,6 +94,11 @@ jsbeautifier==1.15.4 \
# via
# cssbeautifier
# djlint
json-log-formatter==1.1.1 \
--hash=sha256:0815e3b4469e5c79cf3f6dc8a0613ba6601f4a7464f85ba03655cfa6e3e17d10
# via
# -r requirements/base.txt
# django-datadog-logger
json5==0.10.0 \
--hash=sha256:19b23410220a7271e8377f81ba8aacba2fdd56947fbb137ee5977cbe1f5e8dfa \
--hash=sha256:e66941c8f0a02026943c52c2eb34ebeb2a6f819a0be05920a6f5243cd30fd559
Expand Down Expand Up @@ -469,7 +486,3 @@ tqdm==4.67.1 \
--hash=sha256:26445eca388f82e72884e0d580d5464cd801a3ea01e63e5601bdff9ba6a48de2 \
--hash=sha256:f8aef9c52c08c13a65f30ea34f4e5aac3fd1a34959879d7e59e63027286627f2
# via djlint
typing-extensions==4.12.2 \
--hash=sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d \
--hash=sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8
# via -r requirements/base.txt

0 comments on commit c911349

Please sign in to comment.