Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(settings): add LOGGING config #63

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all 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
60 changes: 60 additions & 0 deletions apis_ontology/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,66 @@

WSGI_APPLICATION = "apis_ontology.wsgi.application"

# Custom Django logging
DJANGO_LOG_HANDLERS = ["apis_ontology.console"]

DJANGO_LOG_HANDLERS = os.getenv(
"DJANGO_LOG_HANDLERS", ",".join(DJANGO_LOG_HANDLERS)
).split(",")

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "[{asctime}] {name} {levelname}: {module}.{funcName}:{lineno} {message}",
"style": "{",
"datefmt": "%d/%b/%Y %H:%M:%S", # replicates django.server format
},
"detailed": {
"format": "[{asctime}] {name} {levelname}: {message}",
"style": "{",
"datefmt": "%d/%b/%Y %H:%M:%S",
},
"concise": {
"format": "[{asctime}] {levelname}: {message}",
"style": "{",
"datefmt": "%d/%b/%Y %H:%M:%S",
},
},
"handlers": {
"": {
"class": "logging.NullHandler",
},
"apis_ontology.console": {
"class": "logging.StreamHandler",
"formatter": os.getenv("DJANGO_LOG_FORMATTER", "detailed"),
},
"imports.file": {
"class": "logging.FileHandler",
"filename": os.getenv("DJANGO_LOG_FILE", "imports.log"),
"formatter": "verbose",
},
},
"loggers": {
"apis_ontology": {
"handlers": ["apis_ontology.console"],
"level": os.getenv("DJANGO_LOG_LEVEL", "WARNING"),
"propagate": False,
},
"apis_ontology.scripts": {
"handlers": DJANGO_LOG_HANDLERS, # defaults to apis_ontology.console
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
"propagate": False,
},
"apis_ontology.management.commands": {
"handlers": DJANGO_LOG_HANDLERS,
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
"propagate": False,
},
},
}

# Django Allow CIDR
# see https://github.com/mozmeao/django-allow-cidr
# address '10.0.0.0/8' needs to be allowed for service health checks
Expand Down
Loading