From b7d7e7098d168c53145f3b4b069a75969b5c3cfa Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Wed, 23 May 2018 15:36:18 +0200 Subject: [PATCH] Configure logging --- manuels/views.py | 9 ++++----- manuels_collection/settings.py | 29 ++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/manuels/views.py b/manuels/views.py index 846b782..7ecd8dc 100644 --- a/manuels/views.py +++ b/manuels/views.py @@ -1,16 +1,15 @@ -import os - -from django.conf import settings from django.contrib import messages -from django.core.mail import EmailMultiAlternatives from django.shortcuts import get_object_or_404, redirect -from django.template.loader import render_to_string from django.urls import reverse from django.views.generic import CreateView, ListView from manuels.forms import AddBookForm, AddSuppliesForm from manuels.models import Teacher, Book, SuppliesRequirement +import logging + +logger = logging.getLogger(__name__) + class HomePageView(CreateView): model = Teacher diff --git a/manuels_collection/settings.py b/manuels_collection/settings.py index 01a4736..3acd60f 100644 --- a/manuels_collection/settings.py +++ b/manuels_collection/settings.py @@ -17,7 +17,6 @@ import dj_database_url BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ @@ -27,7 +26,7 @@ SECRET_KEY = os.getenv('SECRET_KEY', 'f6j7c0j%-^$r6&hf4!=db1=)88&ve3qwbsgl3ykd22 # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.getenv('DJANGO_ENV', 'prod') == 'dev' -ALLOWED_HOSTS = ['web',] +ALLOWED_HOSTS = ['web', ] if DEBUG: ALLOWED_HOSTS.extend([ 'localhost', @@ -89,7 +88,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'manuels_collection.wsgi.application' - # Database # https://docs.djangoproject.com/en/2.0/ref/settings/#databases @@ -97,7 +95,6 @@ DATABASES = { 'default': dj_database_url.config(default='sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3'), conn_max_age=600) } - # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators @@ -116,7 +113,6 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] - # Internationalization # https://docs.djangoproject.com/en/2.0/topics/i18n/ @@ -130,6 +126,29 @@ USE_L10N = True USE_TZ = True +# Logging +LOG_LEVEL = 'DEBUG' if DEBUG else 'INFO' +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'verbose': { + 'format': '[%(asctime)s] [%(process)d] [%(levelname)s] %(module)s - %(message)s' + }, + }, + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler', + 'formatter': 'verbose' + }, + }, + 'loggers': { + 'manuels': { + 'handlers': ['console'], + 'level': LOG_LEVEL + }, + }, +} # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.0/howto/static-files/