Skip to content

Instantly share code, notes, and snippets.

@aybruhm
Last active May 27, 2023 12:48
Show Gist options
  • Save aybruhm/81d193ef23a01ed6c9682c33c8a84901 to your computer and use it in GitHub Desktop.
Save aybruhm/81d193ef23a01ed6c9682c33c8a84901 to your computer and use it in GitHub Desktop.
This code snippet is a configuration if you wish to log your Django application.
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Logging configuration
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"file": {
"level": "WARNING",
"class": "logging.FileHandler",
"filename": os.path.join(BASE_DIR, "filename.log"),
"formatter": "standard",
},
},
"formatters": {
"standard": {
"format": "%(asctime)s [%(levelname)s] - %(message)s",
},
},
"loggers": {
"django": {
"handlers": ["file"],
"level": "WARNING",
"propagate": True,
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment