I'm learning to log and I'm not sure what I'm supposed to do with the logger in my view since what I've read around doesn't seem to work or I'm just not understanding something.
This are my settings for the logging:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'todo': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
'propagate': True,
},
},
}
This is the view and the logging part:
from rest_framework import generics, filters
from todo import models
from .serializers import TaskSerializer
from django_filters.rest_framework import DjangoFilterBackend
import logging
logger = logging.getLogger(__name__)
def myview(request):
logger.error('Something went wrong')
class ListTask(generics.ListCreateAPIView):
"""
API view to retrieve list of tasks or create new tasks
"""
queryset = models.Task.objects.all()
serializer_class = TaskSerializer
filter_backends = [DjangoFilterBackend, filters.SearchFilter]
filterset_fields = ['date']
search_fields = ['description']
class DetailTask(generics.RetrieveDestroyAPIView):
"""
API view to retrieve or delete a task
"""
queryset = models.Task.objects.all()
serializer_class = TaskSerializer
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…