{{{
Traceback (most recent call last):
File "/usr/lib/python2.7/logging/__init__.py", line 861, in emit
msg = self.format(record)
File "/usr/lib/python2.7/logging/__init__.py", line 734, in format
return fmt.format(record)
File "<path_to_project>/mwe/venv/local/lib/python2.7/site-
packages/django/utils/log.py", line 173, in format
if args[1][0] == '2':
IndexError: tuple index out of range
}}}
follow these steps:
1) create a project "django-admin startproject <project_name>"
2) put the following into settings.py
{{{
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'custom': {
'()': 'django.utils.log.ServerFormatter',
'format': '[%(server_time)s] %(message)s %(request)r',
}
},
'handlers': {
'custom': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'custom',
},
},
'loggers': {
'django.request': {
'handlers': ['custom'],
'level': 'DEBUG',
'propagate': False,
},
}
}
}}}
3) run the server "python manage.py runserver"
4) navigate to <server>/foobar
The traceback should be printed in the console.
TBH I was sure what to expect as the documentation
(https://docs.djangoproject.com/en/1.10/topics/logging/#django-request)
doesn't make it clear if the django.request logger is used when using the
runserver command, especially when django.server essentially replicates
django.request when running using runserver.
The error occurs (I think) as the format method expects args to be a tuple
consisting of the url, the response status code, and a number (the amount
of data transferred?) but instead receives a tuple containing only the
url.
--
Ticket URL: <https://code.djangoproject.com/ticket/27233>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Unless you say where the bug is, it looks invalid to me to use
'django.utils.log.ServerFormatter' attached to a logger other than
'django.server`'.
--
Ticket URL: <https://code.djangoproject.com/ticket/27233#comment:1>
Comment (by ben-whale):
Replying to [comment:1 timgraham]:
> Unless you say where the bug is, it looks invalid to me to use
'django.utils.log.ServerFormatter' attached to a logger other than
'django.server`'.
Haha ha ha. Yes. Yes it is. Some debugging latter and I can see that you
are quite right.
--
Ticket URL: <https://code.djangoproject.com/ticket/27233#comment:2>
* status: new => closed
* resolution: => invalid
--
Ticket URL: <https://code.djangoproject.com/ticket/27233#comment:3>