[Django] #25321: Logging throws exception because of the formatter string for django.db.backends logger

52 views
Skip to first unread message

Django

unread,
Aug 28, 2015, 10:59:00 AM8/28/15
to django-...@googlegroups.com
#25321: Logging throws exception because of the formatter string for
django.db.backends logger
----------------------------------------------+-------------------------
Reporter: netpositive36 | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords: logging, db
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+-------------------------
It fails on everything written in the logging message format (except
asctime) so the extra parameters (duration, sql, etc.) mentioned in the
documentation doesn't work.

{{{
#!python

# LOGGING
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
},
# Temporary SuspiciousOperation filter
'skip_suspicious_operations': {
'()': 'django.utils.log.CallbackFilter',
'callback': skip_suspicious_operations,
},
},
'formatters': {
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
},
'simple': {
'format': '> %(levelname)-8s %(message)s'
},
'verbose': {
'format': '%(levelname)-8s %(message)s [%(asctime)s
%(filename)s:%(funcName)s:%(lineno)d]'
},
'simple_sql': {
'format': '%% %(asctime)s %(duration).3f %(sql)s' #
},
},
'handlers': {
'null': {
'level':'DEBUG',
'class':'django.utils.log.NullHandler',
},
'console':{
'level':'DEBUG',
'class':'logging.StreamHandler',
'formatter': 'simple'
},
'console_sql':{
'level':'DEBUG',
'class':'logging.StreamHandler',
'formatter': 'simple_sql'
},
'sql_log_file': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': APP_LOG_HOME + 'django_sql_log.log',
'maxBytes': 1024*1024*10, # 10 MB
'backupCount': 10,
'formatter':'simple_sql',
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false',
'skip_suspicious_operations'], # Temporary SuspiciousOperation filter
'class': 'common.log.AdminMultilineEmailHandler'
#'django.utils.log.AdminEmailHandler',
},
},
'loggers': {
'': {
'handlers': ['console', 'log_file'],
'level': 'DEBUG',
'propagate': False,
},
'z.caching': {
'handlers': ['null'],
'level': 'DEBUG',
'propagate': False,
},
'django.db.backends': {
'handlers': ['sql_log_file'],
'level': 'DEBUG',
'propagate': False,
},
'django': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
'django.request': {
'handlers': ['console', 'mail_admins'],
'level': 'DEBUG',
'propagate': False
},
}
}

}}}


{{{
#!python

Traceback (most recent call last):
File
"/usr/local/Cellar/python/2.7.10_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/handlers.py",
line 76, in emit
if self.shouldRollover(record):
File
"/usr/local/Cellar/python/2.7.10_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/handlers.py",
line 156, in shouldRollover
msg = "%s\n" % self.format(record)
File
"/usr/local/Cellar/python/2.7.10_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py",
line 732, in format
return fmt.format(record)
File
"/usr/local/Cellar/python/2.7.10_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py",
line 474, in format
s = self._fmt % record.__dict__
KeyError: 'duration'
Logged from file schema.py, line 102

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25321>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 28, 2015, 11:17:19 AM8/28/15
to django-...@googlegroups.com
#25321: Logging throws exception because of the formatter string for
django.db.backends logger
-------------------------------------+-------------------------------------

Reporter: netpositive36 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:

Keywords: logging, db | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

It looks like you are also handling messages from the
`'django.db.backends.schema'` logger which doesn't include `duration`.
Perhaps a documentation update could clarify this?

--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:1>

Django

unread,
Aug 28, 2015, 2:10:55 PM8/28/15
to django-...@googlegroups.com
#25321: Logging throws exception because of the formatter string for
django.db.backends logger
-------------------------------------+-------------------------------------

Reporter: netpositive36 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: logging, db | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by netpositive36):

Replying to [comment:1 timgraham]:


> It looks like you are also handling messages from the
`'django.db.backends.schema'` logger which doesn't include `duration`.
Perhaps a documentation update could clarify this?

Yes, it'd be awesome.

--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:2>

Django

unread,
Aug 28, 2015, 2:31:30 PM8/28/15
to django-...@googlegroups.com
#25321: Make it clear that django.db.backends.schema messages (which can propogate
to django.db.backends) don't include 'duration'
--------------------------------------+------------------------------------
Reporter: netpositive36 | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: logging, db | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
* component: Database layer (models, ORM) => Documentation
* easy: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:3>

Django

unread,
Oct 16, 2015, 2:22:09 PM10/16/15
to django-...@googlegroups.com
#25321: Make it clear that django.db.backends.schema messages (which can propogate
to django.db.backends) don't include 'duration'
-------------------------------------+-------------------------------------
Reporter: netpositive36 | Owner:
Type: | romanfuentes
Cleanup/optimization | Status: assigned

Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: logging, db | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by romanfuentes):

* owner: nobody => romanfuentes
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:4>

Django

unread,
Nov 17, 2015, 8:08:56 PM11/17/15
to django-...@googlegroups.com
#25321: Make it clear that django.db.backends.schema messages (which can propogate
to django.db.backends) don't include 'duration'
--------------------------------------+------------------------------------
Reporter: netpositive36 | Owner:
Type: Cleanup/optimization | Status: new

Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: logging, db | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* status: assigned => new
* owner: romanfuentes =>


--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:5>

Django

unread,
Nov 22, 2015, 6:45:01 AM11/22/15
to django-...@googlegroups.com
#25321: Make it clear that django.db.backends.schema messages (which can propogate
to django.db.backends) don't include 'duration'
--------------------------------------+------------------------------------
Reporter: netpositive36 | Owner: koxt
Type: Cleanup/optimization | Status: assigned

Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: logging, db | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by koxt):

* owner: => koxt


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:6>

Django

unread,
Feb 9, 2016, 1:10:08 PM2/9/16
to django-...@googlegroups.com
#25321: Make it clear that django.db.backends.schema messages (which can propogate
to django.db.backends) don't include 'duration'
--------------------------------------+------------------------------------
Reporter: netpositive36 | Owner:
Type: Cleanup/optimization | Status: new

Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: logging, db | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* owner: koxt =>


* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:7>

Django

unread,
Mar 8, 2016, 5:30:26 PM3/8/16
to django-...@googlegroups.com
#25321: Make it clear that django.db.backends.schema messages (which can propogate
to django.db.backends) don't include 'duration'
--------------------------------------+------------------------------------
Reporter: netpositive36 | Owner: akki
Type: Cleanup/optimization | Status: assigned

Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: logging, db | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by akki):

* owner: => akki


* status: new => assigned

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/6256

--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:8>

Django

unread,
Mar 9, 2016, 12:55:22 PM3/9/16
to django-...@googlegroups.com
#25321: Make it clear that django.db.backends.schema messages (which can propogate
to django.db.backends) don't include 'duration'
--------------------------------------+------------------------------------
Reporter: netpositive36 | Owner: akki
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: logging, db | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:9>

Django

unread,
Mar 14, 2016, 6:46:29 AM3/14/16
to django-...@googlegroups.com
#25321: Make it clear that django.db.backends.schema messages (which can propogate
to django.db.backends) don't include 'duration'
--------------------------------------+------------------------------------
Reporter: netpositive36 | Owner: MarkusH

Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: logging, db | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by MarkusH):

* owner: akki => MarkusH
* needs_better_patch: 1 => 0


Comment:

PR updated: https://github.com/django/django/pull/6289

--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:10>

Django

unread,
Mar 14, 2016, 9:34:16 AM3/14/16
to django-...@googlegroups.com
#25321: Make it clear that django.db.backends.schema messages (which can propogate
to django.db.backends) don't include 'duration'
-------------------------------------+-------------------------------------
Reporter: netpositive36 | Owner: MarkusH
Type: | Status: assigned
Cleanup/optimization |

Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: logging, db | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:11>

Django

unread,
Mar 15, 2016, 2:47:57 AM3/15/16
to django-...@googlegroups.com
#25321: Make it clear that django.db.backends.schema messages (which can propogate
to django.db.backends) don't include 'duration'
-------------------------------------+-------------------------------------
Reporter: netpositive36 | Owner: MarkusH
Type: | Status: closed

Cleanup/optimization |
Component: Documentation | Version: 1.8
Severity: Normal | Resolution: fixed

Keywords: logging, db | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Markus Holtermann <info@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"1cb65b8a77bd1b15f094b5857468c107784aad90" 1cb65b8a]:
{{{
#!CommitTicketReference repository=""
revision="1cb65b8a77bd1b15f094b5857468c107784aad90"
Fixed #26157 #25321 -- Added sql/params to extra context of schema logger

Thanks Akshesh Doshi for the initial patch and Tim Graham for the review
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25321#comment:12>

Reply all
Reply to author
Forward
0 new messages