Created
December 12, 2019 10:59
-
-
Save vikas-git/5b93689d56c08e599ea996642a6053d8 to your computer and use it in GitHub Desktop.
Use of logger in django project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# setting.py file | |
''' | |
JS logger configuration used in application | |
''' | |
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/jiffyshiplog.log', | |
'maxBytes': 1024*1024*5, # 5 MB | |
'backupCount': 5, | |
'formatter':'standard', | |
}, | |
'request_handler': { | |
'level':'DEBUG', | |
'class':'logging.handlers.RotatingFileHandler', | |
'filename': 'logs/django_request.log', | |
'maxBytes': 1024*1024*5, # 5 MB | |
'backupCount': 5, | |
'formatter':'standard', | |
}, | |
'background_task_handler': { | |
'level':'DEBUG', | |
'class':'logging.handlers.RotatingFileHandler', | |
'filename': 'logs/process_tasks.log', | |
'maxBytes': 1024*1024*5, # 5 MB | |
'backupCount': 5, | |
'formatter':'standard', | |
}, | |
# 'console': { | |
# 'level': 'DEBUG', | |
# # 'filters': ['require_debug_true'], | |
# 'class': 'logging.StreamHandler', | |
# #'formatter': 'verbose' | |
# 'formatter':'standard', | |
# }, | |
}, | |
'loggers': { | |
'': { | |
'handlers': ['default'], | |
'level': 'DEBUG', | |
'propagate': True | |
}, | |
'django.request': { | |
'handlers': ['request_handler'], | |
'level': 'DEBUG', | |
'propagate': False | |
}, | |
'background_task.management.commands.process_tasks': { | |
'handlers': ['background_task_handler'], | |
'level': 'DEBUG', | |
'propagate': False | |
}, | |
# 'django.db.backends': { | |
# 'handlers': ['console'], | |
# 'propagate': False, | |
# 'level': 'DEBUG', | |
# }, | |
} | |
} | |
# in view | |
import logging | |
logging.info("message") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment