Add logging framework usage example

This commit is contained in:
Andrew Smirnov 2021-02-18 20:45:56 +03:00
parent 46dc0f6ab6
commit ca1fab09c9
No known key found for this signature in database
GPG Key ID: 0EFE318E5BB2A82A
2 changed files with 41 additions and 1 deletions

View File

@ -127,3 +127,41 @@ MEDIA_URL = '/media/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
# Logging system
# https://docs.djangoproject.com/en/3.1/topics/logging/
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
'style': '{',
},
'simple': {
'format': '{levelname} {message}',
'style': '{',
},
},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
}
},
'loggers': {
'django': {
'handlers': ['console'],
'propagate': True,
},
'main.index': {
'handlers': ['console'],
'level': 'INFO',
}
}
}

View File

@ -10,7 +10,7 @@ from django_registration.views import RegistrationView
from django.contrib.auth.decorators import login_required
from zenpy import Zenpy
import logging
class CustomRegistrationView(RegistrationView):
@ -69,4 +69,6 @@ def profile_page(request):
def main_page(request):
logger = logging.getLogger('main.index')
logger.info('Index page opened')
return render(request, 'pages/index.html')