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")
------------------
# 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
Post a Comment