Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

DPM 202 asim formatter logging #893

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
path: cypress/screenshots
docs-build:
docker:
- image: python:3.8
- image: python:3.12
steps:
- checkout
- dotenv/source:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8
FROM python:3.12

RUN mkdir /usr/src/app
WORKDIR /usr/src/app
Expand Down
47 changes: 27 additions & 20 deletions app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,57 @@

import logging.config
import os
import sys
from urllib.parse import urlencode

import environ
import sentry_sdk
from django.core.exceptions import ImproperlyConfigured
from django.urls import reverse_lazy
from django.utils import timezone
from django_log_formatter_asim import ASIMFormatter
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.django import DjangoIntegration

environ.Env.read_env() # read the .env file which should be in the same folder as settings.py
env = environ.Env()

logging.config.dictConfig({
# Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'console': {
'format': '[%(asctime)s] [%(levelname)-4s] %(name)-8s: %(message)s',
'datefmt': '%d-%m-%Y %H:%M:%S'
'verbose': {
'format': '%(asctime)s [%(levelname)s] [%(name)s] %(message)s'
},
'asim_formatter': {
'()': ASIMFormatter,
},
'file': {
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
}
},
'handlers': {
'console': {
'asim': {
'class': 'logging.StreamHandler',
'formatter': 'console'
'formatter': 'asim_formatter',
'stream': sys.stdout,
},
'file': {
'level': 'DEBUG' if env.bool('DEBUG') else 'INFO',
'class': 'logging.FileHandler',
'formatter': 'file',
'filename': '/tmp/debug.log'
}
},
'root': {
'level': 'INFO',
'handlers': ['asim'],
},
'loggers': {
'': {
'django': {
'level': 'INFO',
'handlers': ['console', 'file']
}
}
})
'handlers': ['asim'],
'propagate': False,
},
'django.db.backends': {
'level': 'ERROR',
'handlers': ['asim'],
'propagate': False,
},
},
}

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down
33 changes: 33 additions & 0 deletions app/settings/e2etest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
from app.settings.common import *

ROOT_URLCONF = 'app.testfixtureapi_urls'

# For local/E2E tests use "plain" logging (read non ASIM formatted)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'console': {
'format': '[%(asctime)s] [%(levelname)-4s] %(name)-8s: %(message)s',
'datefmt': '%d-%m-%Y %H:%M:%S'
},
'file': {
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'console'
},
'file': {
'level': 'DEBUG' if env.bool('DEBUG') else 'INFO',
'class': 'logging.FileHandler',
'formatter': 'file',
'filename': '/tmp/debug.log'
}
},
'loggers': {
'': {
'level': 'INFO',
'handlers': ['console', 'file']
}
}
}
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
re.MULTILINE | re.DOTALL).group(1)

intersphinx_mapping = {
"python": ("https://docs.python.org/3.8", None),
"python": ("https://docs.python.org/3.12", None),
"django": (
"https://docs.djangoproject.com/en/dev/",
"https://docs.djangoproject.com/en/dev/_objects/",
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[pytest]
DJANGO_SETTINGS_MODULE = app.settings.djangotest
python_files = tests.py test_*.py
# pythonpath = . tests app app/pingdom/tests pingdom

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we don't.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ django-cache-memoize==0.2.0
django-environ==0.11.2
django-extensions==3.2.3
django-filter==24.2
django-log-formatter-asim==0.0.4
django-redis==5.4.0
django-rest-knox==4.2.0
django-staff-sso-client==4.2.2
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.8.18
python-3.12.0