How to write logging in django

settings.py
------------------
# https://docs.python.org/2/library/logging.html#logrecord-attributes
 

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters':{
        'details':{
            'format':'%(asctime)s %(process)d %(filename)s %(funcName)s %(lineno)d %(levelname)s %(message)s'
        },
    },
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename':
'location for/ log file/debug.log',
            'formatter': 'details',
        },
    },
    'loggers': {
        'employee.views': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
    },
}


views.py
--------------

import logging
#Logging object
logger = logging.getLogger(__name__)




def test_view(request):
    logger.info("logout success")

Comments

Popular posts from this blog

AttributeError: Got AttributeError when attempting to get a value for field `abc` on serializer `PfleSerializer`. The serializer field might be named incorrectly and not match any attribute or key on the `QuerySet` instance. Original exception text was: 'QuerySet' object has no attribute 'abc'.

ImportError: No module named regex