Thank You Mr. Russell Keith-Magee. I want to log other details regarding the application. So I selected the django logging.
LOG_URL = '/var/log/Crime_Mapping/' import logging class CustomQueryFilter(logging.Filter): def filter(self, record): for action in ['INSERT', 'UPDATE', 'DELETE']: if action in getattr(record, 'sql', ''): return True return False LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse', }, 'db_query_filter': { '()': CustomQueryFilter, }, }, 'formatters': { 'verbose': { 'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(module)s %(process)d %(thread)d %(message)s", 'datefmt' : "%d/%b/%Y %H:%M:%S" }, 'simple': { 'format': '%(levelname)s %(message)s' }, }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' }, 'file':{ 'level': 'DEBUG', 'filters': ['db_query_filter'], 'class': 'logging.FileHandler', 'filename': LOG_URL+'crime_log.log', 'formatter': 'verbose' }, }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, 'my_logger': { 'handlers': ['file'], 'level': 'DEBUG', }, 'django.db': { 'level': 'DEBUG', 'handers': ['file'], 'filters': ['db_query_filter'], 'propagate': True, }, } } But i get all queries in my log file On Friday, 14 March 2014 08:25:38 UTC+5:30, Russell Keith-Magee wrote: > > Hi Anju, > > Firstly - if you want to filter log messages that meet a specific > criterion, you can install a filter into your logging configuration. Python > and Django's logging documentation both contain sections about filtering: > > http://docs.python.org/2/library/logging.html#filter-objects > https://docs.djangoproject.com/en/dev/topics/logging/#id4 > > Secondly - I'd be questioning whether Django is the right place to be > logging this. Your database also has logging capabilities; I'd be looking > to see whether you can configure your database to produce the logs you need. > > Yours, > Russ Magee %-) > > > > On Thu, Mar 13, 2014 at 3:18 PM, Anju SB <anju...@gmail.com > <javascript:>>wrote: > >> Dear All, >> >> I am a newbie in Django programming. I want to log insert, update, >> delete and failed select query in my daily log file. I configured >> 'django.db.backends' in the logger of the Logging dict in Settings.py. But >> I get all the queries in that application. I need only insert, update, >> delete and failed select queries. >> >> Please help me >> >> Thanking you >> >> Anju >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users...@googlegroups.com <javascript:>. >> To post to this group, send email to django...@googlegroups.com<javascript:> >> . >> Visit this group at http://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/4b34ac77-5a38-46e1-875e-f74c600c7e08%40googlegroups.com<https://groups.google.com/d/msgid/django-users/4b34ac77-5a38-46e1-875e-f74c600c7e08%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8e2bc20e-276a-4cdc-a282-aa783e0998f6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.