Why doesn't logging work on django site?

This is what I tried. In my view.py file,

import logging
logger = logging.getLogger("mylog")
logging.basicConfig(format='%(name)s:%(levelname)s:%(message)s',level=logging.INFO,datefmt='%d/%m/%y %I:%M:%S')

Then inside the function

logger.debug("this is an error")
logger.warning("This is a warning")
print "This is a test line '

I did not touch the settings.py file. Almost the same.

LOGGING = {

    'version': 1,

    'disable_existing_loggers': False,

    'handlers': {

        'mail_admins': {

            'level': 'ERROR',

            'class': 'django.utils.log.AdminEmailHandler'

        }

    },

    'loggers': {

        'django.request': {

            'handlers': ['mail_admins'],

            'level': 'ERROR',

            'propagate': True,

        },

    }

When I start the server and call the function, nothing happens. no mistake, nothing.

I just want to see the log line in the console.

+5
source share
1 answer

Try adding this to handlers:

'console':{
            'level':'DEBUG',
            'class':'logging.StreamHandler',
            'formatter': 'simple'
           }

and in registrars:

    'django': {
        'handlers':['console'],
        'propagate': True,
        'level':'INFO',
    },

. , , , , . - .

EDIT. @jpic .

+10

All Articles