diff --git a/.env.example b/.env.example index ff691cb55..61b6f00ca 100644 --- a/.env.example +++ b/.env.example @@ -59,6 +59,8 @@ DJANGO_SETTINGS_MODULE=redbox_app.settings DEBUG=True DJANGO_SECRET_KEY=1n53cur3K3y DJANGO_LOG_LEVEL=DEBUG +# If you want to disable asim_log formatting comment out below line +DJANGO_LOG_FORMAT=asim_formatter ENVIRONMENT=LOCAL POSTGRES_USER=redbox-core POSTGRES_DB=redbox-core diff --git a/django_app/poetry.lock b/django_app/poetry.lock index 2fe5c5e3b..99e21424d 100644 --- a/django_app/poetry.lock +++ b/django_app/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "aiohappyeyeballs" @@ -1727,6 +1727,21 @@ files = [ django-compressor = ">=1.3" libsass = ">=0.7.0,<1" +[[package]] +name = "django-log-formatter-asim" +version = "0.0.6" +description = "Formats Django logs in ASIM format." +optional = false +python-versions = "<4,>=3.9" +files = [ + {file = "django_log_formatter_asim-0.0.6-py3-none-any.whl", hash = "sha256:00923cb95b599082d94895af1333d1bb8fce05a3d742dd571d32b7e0e480ead3"}, + {file = "django_log_formatter_asim-0.0.6.tar.gz", hash = "sha256:ba35df7a8c5f5bad2e006b55dea8e339ef82f7476a93e6cae4d2bbea12938c2b"}, +] + +[package.dependencies] +django = {version = ">=3,<6", markers = "python_version >= \"3.10\" and python_version < \"4\""} +pre-commit = ">=3.5.0,<4.0.0" + [[package]] name = "django-magic-link" version = "1.0.0" @@ -6299,4 +6314,4 @@ testing = ["coverage[toml]", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = ">=3.12,<3.13" -content-hash = "e73ca2eacb05493947fe008d23e224d4df8708cc73894e07d631bbce9a26c7f1" +content-hash = "88988127b70f28820042586a4d537cd14d5d33375552238051a41e37f5883c79" diff --git a/django_app/pyproject.toml b/django_app/pyproject.toml index bddc608ff..f82c45773 100644 --- a/django_app/pyproject.toml +++ b/django_app/pyproject.toml @@ -48,6 +48,7 @@ scikit-learn = "^1.5.2" django-staff-sso-client = "^4.3.0" dj-database-url = "^2.3.0" dbt-copilot-python = "^0.2.2" +django-log-formatter-asim = "^0.0.6" [tool.poetry.group.dev.dependencies] pytest = "^8.3.2" diff --git a/django_app/redbox_app/settings.py b/django_app/redbox_app/settings.py index 60e6b5a76..db6fd5af1 100644 --- a/django_app/redbox_app/settings.py +++ b/django_app/redbox_app/settings.py @@ -10,6 +10,7 @@ import sentry_sdk from dbt_copilot_python.database import database_from_env from django.urls import reverse_lazy +from django_log_formatter_asim import ASIMFormatter from dotenv import load_dotenv from import_export.formats.base_formats import CSV from sentry_sdk.integrations.django import DjangoIntegration @@ -279,7 +280,7 @@ ALLOWED_HOSTS = ENVIRONMENT.hosts else: LOCALHOST = socket.gethostbyname(socket.gethostname()) - ALLOWED_HOSTS = ['*'] + ALLOWED_HOSTS = ["*"] if not ENVIRONMENT.is_local: @@ -306,7 +307,7 @@ def filter_transactions(event): ) SENTRY_REPORT_TO_ENDPOINT = URL(env.str("SENTRY_REPORT_TO_ENDPOINT", "")) or None -database_credentials = os.getenv('DATABASE_CREDENTIALS') +database_credentials = os.getenv("DATABASE_CREDENTIALS") if database_credentials: DATABASES = database_from_env("DATABASE_CREDENTIALS") DATABASES["default"]["ENGINE"] = "django.db.backends.postgresql" @@ -324,16 +325,22 @@ def filter_transactions(event): } LOG_LEVEL = env.str("DJANGO_LOG_LEVEL", "WARNING") +LOG_FORMAT = env.str("DJANGO_LOG_FORMAT", "verbose") LOGGING = { "version": 1, "disable_existing_loggers": False, - "formatters": {"verbose": {"format": "%(asctime)s %(levelname)s %(module)s: %(message)s"}}, + "formatters": { + "verbose": {"format": "%(asctime)s %(levelname)s %(module)s: %(message)s"}, + "asim_formatter": { + "()": ASIMFormatter, + }, + }, "handlers": { "console": { "level": LOG_LEVEL, "class": "logging.StreamHandler", - "formatter": "verbose", - }, + "formatter": LOG_FORMAT, + } }, "root": {"handlers": ["console"], "level": LOG_LEVEL}, "loggers": {