4

I have logging set-up in my Django 1.9 project. I am getting the logs in django_request.log automatically as expected but not in mylog.log when I use logging in views.py. Where am I wrong?

views.py

import logging
logr = logging.getLogger(__name__)

def sample_view(request):
   logr.debug('Ran Sample view')
   return HttpResponse("Done!")

settings.py

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
        },
    },
    'handlers': {
        'default': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': 'logs/mylog.log',
            'maxBytes': 1024 * 1024 * 5,  # 5MB
            'backupCount': 5,
            'formatter': 'standard'
        },
        'request_handler': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': 'logs/django_request.log',
            'maxBytes': 1024 * 1024 * 5,  # 5MB
            'backupCount': 5,
            'formatter': 'standard'
        },
    },
    'loggers': {
        '': {
            'handlers': ['default'],
            'level': 'DEBUG',
            'propagate': True
        },
        'django.request': {
            'handlers': ['request_handler'],
            'level': 'DEBUG',
            'propagate': False
        },
    }
}
karthikr
  • 97,368
  • 26
  • 197
  • 188
Rk..
  • 753
  • 1
  • 10
  • 27

1 Answers1

1

I found out this "If the disable_existing_loggers key in the LOGGING dictConfig is set to True (which is the default) then all loggers from the default configuration will be disabled. Disabled loggers are not the same as removed; the logger will still exist, but will silently discard anything logged to it, not even propagating entries to a parent logger."

on https://docs.djangoproject.com/en/1.7/topics/logging/#configuring-logging

So if you set 'disable_existing_loggers': False, you will be able to see all logs.

FatmaT
  • 255
  • 1
  • 9