Enable Django logging also if DEBUG is True

django, django-settings

Solution

Django logging is not disabled by default in either DEBUG mode unless you have set it to.

Add below to your `handlers` part of `LOGGING`

'file':
        {
            'level':
                'INFO',
            'class':
                'logging.FileHandler',
            'formatter':
                'verbose',
            'filename':
                'myapp.log'

        }

It will log to `myapp.log` file in your project root. You can specify a complete path.

And add a formatters field to the Logging dict

'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'simple': {
            'format':
                '%(levelname)s %(message)s'
        },
    },

Problem

By reading the official django documentation I haven't understood much about it. https://docs.djangoproject.com/en/dev/topics/logging/#configuring-logging I would like to enable logging also if DEBUG in settings.py is set to True. I would like the errors to be logged in a file. How to do that? These are the default django settings for logging which I currently have now: ``` LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' } }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, } } ``` PS: I'm using Apache + mod_wsgi in my development environment because I use a development machine which i access remotely on my LAN, this means i'm not using the django development server and I can't see the console log messages.

Original source

Related problems